First Class Functions Javascript
- What are First Class Functions?
- In a language where a function can be treated like a variable their functions are called first class functions
- Functions can be passed into another functions, can be used, manipulated & returned, basically, anything a variable can do, a function can also do.
function square (num) {
return num * num;
}
function displaySquare(fn) {
console.log("Square is " + fn(5));
}
displaySquare(square); // function square is passed in another function displaySquare