foundation

Hoisting and bindings

var, let, const, function declarations, temporal dead zone, and initialization timing.

Hoisting means declarations are processed before execution. `function` declarations are fully hoisted and callable before their line. `var` is hoisted and initialized to `undefined`. `let` and `const` are hoisted but live in the temporal dead zone until initialization — reading them early throws `ReferenceError`.

					console.log(kind);
let kind = 'module'; // ReferenceError
				

`const` prevents rebinding the variable, not mutating object contents. A `const` function expression follows TDZ until assignment.

On interviews, explain the concept with a concrete example and name the runtime behavior interviewers probe.

Common pitfalls include mixing similar APIs and forgetting edge cases during live coding.

The trade-off is often clarity versus performance or safety versus convenience.

Checklist:

  • Separate declaration from initialization.
  • Know var function scope versus let/const block scope.
  • Explain TDZ and const binding versus object mutation.