liveBook · Manning

Temporal dead zone

As explained in Acing the Frontend Interview

The temporal dead zone is the interval between entering a scope and initializing a let or const binding during which accessing that binding throws a ReferenceError.

The temporal dead zone (TDZ) is the interval after entering a scope but before initializing a let or const binding. Accessing the binding during this interval throws a ReferenceError, making it a common JavaScript interview test of hoisting and execution phases. section 3.1

Hoisting contrast

function greet() { console.log(message); let message = "Hello, world!"; } greet(); This throws ReferenceError: Cannot access 'message' before initialization. let is hoisted but remains uninitialized in the TDZ. By contrast, var is initialized to undefined during hoisting, so an earlier access produces undefined. Removing strict mode does not change TDZ behavior. section 3.1

Interview follow-ups commonly test whether you can:

  • Compare hoisting for var, let, and const. section 3.1
  • Explain how scope and execution phases affect variable access. section 3.1

How Acing the Frontend Interview covers it

How deep it goes
Explains the access interval, initialization state, ReferenceError, and contrast with var, stopping short of specification internals.
Examples
Uses a greet function that accesses a let binding before its declaration and contrasts the result with var.
What it assumes
Assumes basic JavaScript functions and variables while establishing execution phases, scope, and hoisting context.
What you can do after
Evaluate JavaScript snippets involving hoisting and explain why pre-initialization access throws a ReferenceError.
How it connects
Connects temporal dead zones with hoisting, execution context, scope, initialization, var, let, const, and ReferenceError.

Also explained in

Compare how 2 books explain temporal dead zone →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Frontend Interview. The section links point to the parts of the book it draws on.