Function as data:
A function is a first-class object. Since objects have methods and properties, the function will also have methods and properties.
We can assign functions to variables, and we can reassign them to new variables.
The function that takes one or more functions as arguments (i.e. procedural parameters), returns a function as its result that is called Higher Order Function.
function higherOrderFunction(firstClassFunction) { const val = 20; return firstClassFunction(val); } function firstClassFunction(age) { console.log(age); } higherOrderFunction(firstClassFunction);
First-class function:
The function which is passed as an argument to the higher-order function is called a first-class function.
Now we can reassign the function to a new variable.
Functions as parameters:
A higher-order function is a function that can accept either function as parameters, return functions, or both.
The functions that get passed in as parameters and invoked are known as a callback function.
Post a Comment