Functions as First-Class Citizens in JavaScript
In JS, functions are values. Here is what first-class means and why it enables functional programming.
Functions as First-Class Citizens in JavaScript
In JavaScript, functions are first-class citizens. That means they are treated like any other value. This is the foundation of functional programming in JS.
What First-Class Means
- Functions can be assigned to variables.
- Functions can be passed as arguments to other functions.
- Functions can be returned from other functions.
- Functions have a type (
"function").
Assign to a Variable
const greet = function (name) { return `Hello, ${name}`; }; const greet2 = greet; greet2("Kunal"); // "Hello, Kunal"
Pass as an Argument (Callback)
function process(value, fn) { return fn(value); } process(5, (x) => x * 2); // 10
Return From a Function (Higher-Order)
function multiplier(factor) { return (n) => n * factor; } const double = multiplier(2); double(5); // 10
Store in Data Structures
const ops = { add: (a, b) => a + b, sub: (a, b) => a - b, }; ops.add(2, 3); // 5
Why This Matters
First-class functions enable:
- Callbacks: pass behavior into async APIs (
setTimeout,fetch, event listeners). - Higher-order functions:
map,filter,reduce,compose. - Functional programming: pure functions, immutability, function composition.
- Event handling: register handlers as values.
- Dependency injection: pass strategies into functions.
typeof a Function
typeof (() => {}); // "function"
Functions are objects under the hood. They can have properties (rarely useful, but legal):
function foo() {} foo.counter = 0;
The Takeaway
First-class means functions are values: assignable, passable, returnable, storable. This is what makes callbacks, higher-order functions, and functional programming possible in JavaScript. Everything async in JS relies on this.
Functions are treated like any other value. They can be assigned to variables, passed as arguments, returned from other functions, stored in data structures, and have a type (typeof is 'function').
Yes. Passing functions as arguments is how callbacks work. setTimeout, map, filter, fetch.then, and event listeners all accept functions as arguments.
Yes. A function that returns another function is called a higher-order function. The returned function often captures the outer variable environment, creating a closure.
'function'. Functions are a distinct type, but under the hood they are callable objects. They can even have their own properties, though this is rarely useful.
They enable callbacks, higher-order functions (map, filter, reduce), functional programming (composition, pure functions), and event handling. Almost all async patterns in JS rely on functions being first-class.
Ready to master React completely?
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course to dive deeper with high-quality video tutorials, solve interview questions, and a premium community.
Master React
Want to upskill yourself, crack your next interview, and get your dream job? Join our comprehensive course.

