Function expressions as values
Quick answer
A function expression creates a function value as part of an expression. Store it in a binding or pass it to another function.
How it works
In const double = function(n) { return n * 2; }; the binding is initialized by evaluating the expression. A named function expression has a name visible within its own body; the outer const still follows its temporal dead zone rules.
const twice = function(n) { return n * 2; };const operation = twice;console.log(operation(5));Expected output in Node.js:
10Both bindings hold the same function value.
const describe = function inner() { return typeof inner; };console.log(describe(), typeof inner);Expected output in Node.js:
function undefinedThe inner name is available inside the function, not as an outer binding.
Common mistakes
Do not call a const-bound function before its initialization. Do not assume a named expression creates an outer declaration.
Practice
Store a function that triples a number, assign it to another binding, and call both.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Function expressions as values — Knowledge Check
Apply the taught concept and reason about the result.
What is the value stored by const f = function(){return 2;}?
Given const f=function(){return 7;}; const g=f; what does g() return?
Can a const-bound function expression be called before that binding initializes?
Where is the name in const f = function inner(){} normally visible?
Which assigns a function without executing its body?