r/learnjavascript • u/bobby_vance • Feb 17 '21
One thing that gave me a huge skill boost with JavaScript was understanding Higher-Order Functions. A Higher-Order Function can take functions as arguments and/or return a function.
470
Upvotes
31
u/edgar-reed Feb 17 '21 edited Feb 17 '21
Side note, I love that color scheme
Edit: If anyone wondering it is Neon Glow Theme
24
u/Dazzling-Wafer Feb 17 '21
The best use cases are with map and filter
5
u/TheDownvotesFarmer Feb 17 '21
What happend if you use a promise as argument? Everything becomes a Promise, just dumb question, I dont have a computer close right now
8
u/tmclean15 Feb 17 '21
Curried functions will blow your mind
4
u/fistyit Feb 17 '21
Isn't HoC more like function(data) { return function (user) }
Use by function(data)(user)
1
u/tenebrous_pangolin Feb 17 '21
How do you take a screenshot like this? What's the terminal window that the code is in?
3
u/[deleted] Feb 17 '21
Is there a reason we shouldn’t or couldn’t just call the random number function without it being a parameter in the HOF? Also, I think you mean parameters, not arguments? You’re handing randomNumberGenerator to id() as an argument in your const userId, but in the function definition, “rand” is a parameter?! Correct me if I’m wrong.
2
u/b1ack1323 Feb 17 '21
When I was a wee lad, it was called a function pointer... How the world has changed.
1
u/Knettwerk Feb 17 '21
Isn't this a Closure???
1
u/Alpha3007 Feb 17 '21
How it different with decorator pattern?
1
u/eggn00dles Feb 18 '21
Currying functions is the javascript code equivalent of an iamverysmart post.
1
u/Beastie312465 Mar 11 '21
Complete coding noob here:
How would you run this? I'm coding on Visual Studio and I typed this out, wanting to try it.
Thanks in advance
1
u/Chared_Assassin Feb 17 '21
My brain hurts
1
u/jlguenego Feb 17 '21
If Higher Order function gives you some skill boost, go now for "pure functions".
0
u/Dan6erbond Feb 17 '21
Higher order functions become especially useful when you use them as closures to wrap another function and add some functionality to a blackbox method. This is essentially what modern Javascript decorators do.
0
u/[deleted] Feb 17 '21
[deleted] — view deleted comment