Built-in higher-order functions:
Numerous in-built JavaScript operations on arrays
, DOM methods
, strings
, promise methods
, and so on are higher-order functions that offer substantial abstraction.
Here are some of the several built-in higher-order functions:
Array.prototype.map():
Themap()
method generates a new array by invoking the callback function given as a parameter for each input array element. Themap()
method takes each value returned by the callback function and uses these values to form a new array.Array.prototype.reduce():
The reduction method applies the callback function to each element of the calling array, resulting in a single output value. Thereduce
method uses two arguments: the reducer function and the optionalinitialValue
. A single value is returned after applying the reducer to each array element.EventTarget.addEventListener():
When called on an EventTarget, the addEventListener() function adds the given listener to that target. An event-supporting object, such as an Element inside a document, a window, or another event-supporting object, can serve as the event target (likeXMLHttpRequest
).Array.prototype.filter():
Thefilter()
method generates a shallow duplicate of a piece of an array, filtered to include only the array elements that satisfy the provided function's test.Array.prototype.forEach():
TheforEach
method in JavaScript is a function that loops over an array, calling a specified callback function at each iteration. TheforEach
method is fully browser and node supported, asforEach
was incorporated in the ECMAScript 5 specification.