Skip to content
JavaScript·Intermediate·Coding·1 min read

What happens before a function body executes?

Short interview answer

The runtime establishes parameter bindings, local declarations, the lexical environment, and this according to the function's call form. Function declarations are initialized early; let, const, and class bindings exist but remain uninitialized until evaluation reaches them.

Example

JavaScript
foo();                       // "hoisted" — declaration is ready before this lineconsole.log(x);              // undefined — `var x` exists, not yet assignedvar x = 10;function foo() { console.log('hoisted'); }

Key takeaway

Explain the underlying mental model clearly, then support it with a concrete example and its trade-offs.

← Back to Execution context

Related questions