April 2018
Beginner
536 pages
13h 21m
English
A higher-order function is a function that does at least one of the following:
Higher-order functions are one of the most powerful tools that we can use to write JavaScript in an FP style. Let's see some examples.
The following code snippet declares a function named addDelay. The function creates a new function that waits a given number of microseconds before printing a message in the console. The function is considered a higher-order function because it takes a function as one of its arguments:
function addDelay(msg: string, ms: number) { return () => { setTimeout(() => { console.log(msg); }, ms); }; } const delayedSayHello = addDelay("Hello ...