Higher Order Functions in Javascript

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:

  1. Functions inside functions
  2. Functions that change functions
  3. 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”