We have learned about higher-order components, and in this section, we will have a look at the more general concept, called higher-order functions.
Have a look at the example. It's pretty straightforward. You wouldn't even notice you created anything special:
const add5 = x => x + 5; // function
const applyTwice = (f, x) => f(f(x)); // higher order function applyTwice(add5, 7); // 17
So what is a higher-order function?
A higher-order function is a function that does one of the following:
- Takes one or more functions as an argument
- Returns a function
That's it; it's so simple.