What are First-class Functions?
In JavaScript and other functional languages, functions can also be assigned to variables and you can pass them around, just like they were variables.
First-class function are functions that you can:
- Pass as arguments to other functions
- Store them in a variable
- Return as values from other functions
Take the following as an example:
Copied to clipboard! Playground
const greet = function () {
console.log('π');
}
// The greet variable is now a function, we can invoke it
greet();
Here the greet
function is passed around and is treated like a variable.
Resources:
π More Webtips
Rocket Launch Your Career
Speed up your learning progress with our mentorship program. Join as a mentee to unlock the full potential of Webtips and get a personalized learning experience by experts to master the following frontend technologies: