First-class function
A programming language is said to have first-class functions if it treats functions as first-class citizens.
Assign a function to a variable:
const foo = function() {
console.log("foobar");
}
// Invoke it using the variable
foo();Pass a function as an Argument:
function sayHello() {
return "Hello, ";
}
function greeting(helloMessage, name) {
console.log(helloMessage() + name);
}
// Pass `sayHello` as an argument to `greeting` function
greeting(sayHello, "JavaScript!");Return a function:
Last updated