What is the first class function in JavaScript ? Last Updated : 22 Oct, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report First-Class FunctionA 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 treats function as a first-class citizen. This means that functions are simply a value and are just another type of object.Usage of First-Class FunctionIt can be stored as a value in a variable.It can be returned by another function.It can be passed into another function as an Argument.It can also stored in an array, queue, or stack.Also, It can have its own methods and property.Example 1: 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)); Output100 + 100 = 200 100 - 7 = 93 5 * 5 = 25 100 / 5 = 20 Note: In the above example, functions are stored as a variable in an object.Example 2: This example shows more about the first-class function. JavaScript const Geek = (a, b) => { return (a + " " + b); } console.log(Geek("Akshit", "Saxena")); OutputAkshit Saxena Comment More infoAdvertise with us Next Article What is the first class function in JavaScript ? A akshitsaxenaa09 Follow Improve Article Tags : JavaScript Web Technologies Blogathon Blogathon-2021 javascript-basics JavaScript-Questions +2 More Similar Reads What is the (function() { } )() construct in JavaScript? If you've ever played around with JavaScript, you might have seen this expression. It's like a strange set of symbols, but it has a special name that is an immediately invoked function expression, or IIFE. In this article, we will understand each element of the expression as well as the functionalit 3 min read What is First Class Citizen in JavaScript? In JavaScript, a First Class Citizen is an entity that can be assigned to a variable, passed as an argument to a function, returned from a function, and has properties and methods assigned to it. Functions are examples of First Class Citizens in JavaScript. Below are some terms related to First Clas 2 min read What is the syntax for leading bang! in JavaScript function ? Before we get to know the syntax for the leading bang! in a JavaScript function, let's see what functions in JavaScript are actually are. JavaScript functions are a set of statements(procedures) that perform some tasks or calculate some value. A function may take some input and return the result to 2 min read What is a Constructor in JavaScript? A constructor in JavaScript is a special function that is used to create and initialize objects. When we want to create multiple objects with similar properties and methods, the constructor is used as a blueprint to create similar objects. This is useful when you want to create multiple objects with 8 min read What is a typical use case for anonymous functions in JavaScript ? In this article, we will try to understand what exactly an Anonymous function is, and how we could declare it using the syntax provided in JavaScript further we will see some examples (use-cases) where we can use anonymous functions to get our results in the console. Before proceeding with the examp 4 min read Like