A first class function is a function that was built with the intention of being passed around to other functions. It does one specific thing, does not have side effects, and is not intended to be called directly, but rather, to be used by ‘other functions.’
Those ‘other functions’ which accept one of those ‘first class functions’ as an argument are called higher order functions. Higher order functions also might be functions that return a function.
In a higher order function, when one of the parameters passed in is a function, that function is a callback function because it will be called back and used within the higher order function.
A higher order function is named as such because when using a callback to perform an operation within itself, the function has a ‘higher’ purpose than a regular function. When it returns a function, it also has a ‘higher’ purpose.
Assign a function to a variable
Pass a function as an argument
Return a function
Eg. forEach(), find(), filter(), map(), reduce(), sort(), some(), every(), etc.
array.prototype.reduce are some of higher-order functions built into the language.
will run a callback function on every elements in an array and will return either true of false for each item, if true, it will push the item to the new array
The filter() method creates a new array with all elements that pass the test provided by the callback function.
The filter() function will run a callback function on every item in an array and will return either true or false for each of them. If true, it will_ push the item to the new array_. The callback function passed to the
filter() method accepts 3 arguments: element, index, and array.
will run a callback function ( provided as arguments) on every elements in the array and will push each result into a new array
The map() method creates a new array by calling the callback function provided as an argument on every element in the input array.
The map() method will take every returned value from the callback function and creates a new array using those values
Parameter is at the time of declaration, Argument is an actual value of supply for the parameter
Function greet(name) console.log( ‘Hello’+ name) greet(‘john’)