What is a Higher-Order function?
How do functions behave like other data types?
Functions can be assigned to variables and then reassigned to a new variable.
const announceThatIAmDoingImportantWork = () => {
console.log(“I’m doing very important work!”);
};
const busy = announceThatIAmDoingImportantWork;
What do you not do when assigning an existing function to a new variable OR when passing a callback function as an argument.
Do not invoke the function by adding parenthesis ().
Incorrect - const busy = DoingImportantWork();
This assigns the functions return value to the variable.
Correct - const busy = DoingImportantWork;
This assigns the existing function to the new variable.
What is a first-class object?
They have properties and methods. For example a function is a first-class object.
How do you find the original name of a function?
Use the name property.
const isTwoPlusTwo = checkThatTwoPlusTwo;
isTwoPlusTwo();
console.log(isTwoPlusTwo.name);
What is a callback function?
A function that gets passed as an argument to a higher-order function.
The callback function is invoked when the higher-order function is called.
What is an anonymous function?
A function without a name, an anonymous function can be an argument to.