Functions Assigned to Variables
A “higher-order function” is a function that accepts functions as parameters and/or returns a function.
.forEach() method executes a callback function on each of the elements in an array in order.
Here, the callback function containing a
console.log() method will be executed
5 times, once for each element.
.map() method executes a callback function on each element in an array. It returns a new array made up of the return values from the callback function.
The original array does not get altered, and the returned array may contain different elements than the original array.
.filter() method executes a callback function on each element in an array. The callback function for each of the elements must return either
false. The returned array is a new array with any elements for which the callback function returns
Here, the array
filteredArray will contain all the elements of
.reduce() method iterates through an array and returns a single value.
It takes a callback function with two parameters
(accumulator, currentValue) as arguments. On each iteration,
accumulator is the value returned by the last iteration, and the
currentValue is the current element. Optionally, a second argument can be passed which acts as the initial value of the accumulator.
.reduce() method will sum all the elements of the array.