Functions Are First-Class Values

Functions can be assigned to variables, stored in objects, passed as arguments, returned from other functions, and dynamically constructed. This enables callbacks, higher-order functions, event handlers, middleware, composition, and functional programming techniques.

A function declaration and a function expression both create callable functions, but their declaration and initialization behavior differs.

Passing Functions Around
function double(value) {
  return value * 2;
}

function transform(value, operation) {
  return operation(value);
}

console.log(transform(5, double));
💡 The transform function receives another function as an argument. This is the basis of higher-order functions.
Key Takeaways
  • Functions are values in JavaScript.
  • Functions can be passed, returned, stored, and composed.
  • Higher-order functions accept or return functions.
Knowledge Check

What is a higher-order function?