A declaration is a named function statement; an expression assigns a function to a variable. The practical difference is hoisting.
js
();
() { ; }
();
expressed = () { ; };
A declaration is a named function statement; an expression assigns a function to a variable. The practical difference is hoisting.
();
() { ; }
();
expressed = () { ; };
Function declarations are hoisted with their body, so the whole function exists before execution reaches it. A function expression is just a value assigned to a variable — at the point of the early call, expressed is still undefined (with var) or in the TDZ (with let/const).
// expression — for callbacks, conditional definitions, arrow functions
const handler = () => doThing();
const fn = condition ? a : b;
arr.map(x => x * 2);
// declaration — clear, hoisted top-level functions
function calculateTotal(items) { ... }
Declarations read well for top-level named functions and benefit from hoisting (you can define them after their use). Expressions are necessary for arrow functions, callbacks, IIFEs, and assigning functions conditionally. Arrow functions are always expressions.