Saturday, December 13, 2025
HomeLanguagesJavascriptWhat is the first class function in JavaScript ?

What is the first class function in JavaScript ?

First-Class Function: A programming language is said to have First-class functions if functions in that language are treated like other variables. So the functions can be assigned to any other variable or passed as an argument or can be returned by another function. JavaScript treat function as a first-class-citizens. This means that functions are simply a value and are just another type of object.

Example: Let us take an example to understand more about the first-class function.

Javascript




const Arithmetics = {
    add: (a, b) => {
        return `${a} + ${b} = ${a + b}`;
    },
    subtract: (a, b) => {
        return `${a} - ${b} = ${a - b}`
    },
    multiply: (a, b) => {
        return `${a} * ${b} = ${a * b}`
    },
    division: (a, b) => {
        if (b != 0) return `${a} / ${b} = ${a / b}`;
        return `Cannot Divide by Zero!!!`;
    }
 
}
 
console.log(Arithmetics.add(100, 100));
console.log(Arithmetics.subtract(100, 7))
console.log(Arithmetics.multiply(5, 5))
console.log(Arithmetics.division(100, 5));


Note: In the above example, functions are stored as a variable in an object.

Output:

100 + 100 = 200
100 - 7 = 93
5 * 5 = 25
100 / 5 = 20

Example 2: This example shows more about the first-class function

Javascript




const Geek = (a, b) => {
    return (a + " " + b);
}
 
console.log(Geek("Akshit", "Saxena"));


Output:

Akshit Saxena
RELATED ARTICLES

Most Popular

Dominic
32446 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6814 POSTS0 COMMENTS
Nicole Veronica
11952 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12030 POSTS0 COMMENTS
Shaida Kate Naidoo
6949 POSTS0 COMMENTS
Ted Musemwa
7199 POSTS0 COMMENTS
Thapelo Manthata
6896 POSTS0 COMMENTS
Umr Jansen
6882 POSTS0 COMMENTS