” ‘ THIS, SAID LAYELAH, ‘ IS THE WAY WE HAVE OF ESCAPING. ‘ “
const powerOf = (exponent) => {
return num => num ** exponent;
}
1. If you can read this, then you’re able to understand the rest
Higher-order functions are functions that operate on other functions, for example, one of these can take functions as arguments or return another function. We can have three different types of these:
- Functions inside functions
- Functions that change functions
- Function that manage the control flow
Lucky for me, we have here an inner function example inside a mainly function (give a reading to closure). In this example, powerOf
requires an ‘exponent
‘ parameter and returns an anonymous function. The latter, accept a ‘num
‘ parameter which will be multiplied by itself for ‘exponent
‘ times (the ** operator was introduced by ECMAScript7).
Take a deep breath …
Continue reading “Higher Order Functions in Javascript”