First-Class Function
noun
say it: “FURST klass FUNK-shun” /fɜːrst klæs ˈfʌŋkʃən/
The idea that in JavaScript a function is a value like any other: you can keep it in a variable, pass it to another function, or return it from one.
What is First-Class Function in JavaScript?
First-Class Function — A language has first-class functions when a function is a value like any other: you can keep it in a variable, pass it to another function, or return it from one. JavaScript does, and that's what makes callbacks and map() work.
const shout = (name) => name.toUpperCase();
const tidyName = shout; // the same function, in another variable
console.log(['Rae', 'Max'].map(tidyName)); // [ 'RAE', 'MAX' ]
In a sentence
- “Because JavaScript has first-class functions, I could store the greet function in a variable and pass it to a button.”
Level: Journeyman · More JavaScript terms at this level
Updated