Function declaration vs function expression
By FrontendPro Editorial Team Updated 9/26/2026
Answer
A declaration is a statement that defines a named function. An expression produces a function value that you assign somewhere — the function is not the statement, it is part of one.
function declared() {} // declaration
const expressed = function () {}; // expression, anonymous
const named = function inner() {}; // expression, named
const arrow = () => {}; // expression
The syntactic rule is simple: if function is the first token of the statement, it is a declaration; otherwise it is an expression.
Availability
A declaration is fully ready before the scope runs, so it can be called from above. An expression is only as ready as the variable holding it:
declared(); // works
expressed(); // TypeError: expressed is not a function
arrow(); // ReferenceError — const is in the temporal dead zone
The name of a named expression is private
inner above is visible only inside the function itself, not outside. That makes it useful for recursion and for readable stack traces without leaking a name:
const fact = function f(n) {
return n <= 1 ? 1 : n * f(n - 1); // `f` works here
};
f; // ReferenceError — not visible out here
An anonymous expression assigned to a variable still gets an inferred .name ("expressed"), so stack traces are usually fine either way.
Which to use
Expressions assigned to const are the common modern default: the function cannot be called before it exists, cannot be accidentally reassigned, and cannot be silently redefined by a second declaration of the same name. Declarations remain useful for top-level helpers where calling before the definition makes the file read better. Avoid declarations inside blocks (if, for) — their behaviour differs between strict and sloppy mode.
