Why we use the first-class function that really needed in JavaScript.
1.A simple definition of the first-class function is a function that can be passed as an argument to another function.
2.And also returned by another function in JavaScript.
3.or also can be assigned the variable to function.
Some Example with the first-class function:-
function with a variable
const foo = function() {
console.log("foobar");
}
// Invoke it using the variable
foo();
A returned a function using the first-class function
function sayHello() {
return function() {
console.log("Hello!");
}
}
sayHello()();
Thank you!
Top comments (0)