March 2019
Intermediate to advanced
350 pages
7h 28m
English
In JavaScript, functions are first-class objects, which means that they can be assigned to variables and passed as parameters to other functions.
This allows us to introduce the concept of higher-order functions (HoFs). HoFs are functions that take a function as a parameter, optionally some other parameters, and return a function. The returned function is usually enhanced with some special behaviors.
Let's look at a simple example where there is a function for adding two numbers that gets enhanced with a function that first logs all the parameters and then executes the original one:
const add = (x, y) => x + y;const log = fn => (...args) => { console.log(...args); return fn(...args);};const logAdd = log(add);
This ...
Read now
Unlock full access