🟢 EasyFunctions📖 Theory Question

What does it mean that functions are "first-class citizens" in JavaScript?

💡

Hint

Functions are values — assignable, passable, returnable, storable

Full Answer

Functions are first-class citizens — they're treated as values just like strings or numbers. This means:

  • Assign to variables
  • Pass as arguments
  • Return from functions
  • Store in arrays/objects
  • Have properties and methods attached
// Assigned to variable
const greet = (name) => 'Hello, ' + name;

// Passed as argument (callback)
[1, 2, 3].forEach(function(n) { console.log(n); });

// Returned from function
function makeAdder(x) {
  return (y) => x + y; // ← function as return value
}
const add5 = makeAdder(5);
add5(3); // 8

// Stored in object
const math = {
  add: (a, b) => a + b,
  sub: (a, b) => a - b,
};

// Has properties
function fn() {}
fn.version = '1.0';
console.log(fn.name);   // 'fn'
console.log(fn.length); // 0 (param count)
💡 First-class functions are what enable HOFs, callbacks, closures, and all functional programming patterns in JS.

More Functions Questions

🟢 EasyWhat is the difference between call, apply, and bind?🟢 EasyHow do arrow functions differ from regular functions?🟢 EasyWhat is a pure function and why does it matter?🟢 EasyWhat are Higher-Order Functions (HOF)?

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint