Welcome back everyone to another challenge! This is another topic that could be brought up while interviewing for an Engineer/Developer role.
Explain higher order functions in javascript.
This is a function that operate on other functions, either by taking them as arguments, oftened referred as a callback, or by returning them.
In Javascript, functions are treated as first-class citizens, meaning that they can be assigned to a variable and/ or passed as a value.
Example 1:
Example 2:
It’s higher-order because instead of strings, numbers, or booleans, it goes higher to operate on functions. Pretty Cool, right?
The map function on arrays is considered a higher order function. It takes a function as an argument.
Or, as an anonymous function
The map function is one of the many higher-order functions built into JavaScript. Other examples are sort, reduce, filter, and for Each. Learning is so much fun, right?!
I found reading about higher order functions very helpful and I hope you find it helpful too, but don’t just read about it, code about it. It definitely helps stick more. Please join me on my next blog when we go over a new challenge.
Until next time…