Notes from Higher Order Functions in JavaScript

What is a higher order function

Unlike ordinary functions, which are a named block of code with arguments and returns, higher-order functions have two levels of functionalities. This is accomplished by either using functions are arguments and/or returns. A higher-order function takes a function as input or output to enable us to do a lot of interesting things.

Example functions: - map() - reduce() - sort() - filter()

Example code:

function multiplier(factor) {
    return function(x) {
        return x * factor;
    }
}
function(x) {
    return x * factor;
}

The Arrow functions

  • Only available in ES6.

The above method could be succinctly written as:-

function multiplier(factor) {
    return x => x * factor;
}

Arrow functions vs Regular Functions

  • Readable, succinct and simple,
  • An arrow function does not create its own context

Subscribe for coding videos

Keep growing professionally with just three curated videos weekly.

We hate spam as much as you do.