Why first class function
Jul 22, 2023
- Function can be assigned to a variable
const fn = function(name) {
console.log(name);
};
fn("rogerio bispo");2. A function can be a value in an Array
const arr = [
1,
function(n1, n2) {
console.log(n1 + n2);
}
];
arr[1](1, 10);3. A function can be a value in an object
const obj = {Get Rogerio Santos’s stories in your inbox
Join Medium for free to get updates from this writer.
age: 40,
name: function(name) {
console.log(name);
}
};
obj.name("rogerio");
4. Can be passed to a function
const fn = function(name) {
console.log(name)
}
const fn2 = (fn) => fn("Bispo")
fn2(fn)5. Can be returned from a function
const fn3 = () => console.log("returned function");
const fn4 = (fn) => fn;
const returnedFunction = fn4(fn3);
returnedFunction();6. Function can be an IIFE (Immediately Invoked Function Expression)
(() => console.log("IIFE"))();



