← Lessons

quiz vs the machine

Platinum1750

Frontend

The Temporal Dead Zone

Let and const exist but cannot be touched until their declaration runs.

4 min read · advanced · beat Platinum to climb

Hoisted but not usable

Variables declared with let and const are hoisted to the top of their block, just like var. The difference is they are not initialized. From the start of the block until the declaration line executes, they sit in the temporal dead zone, and any access throws a ReferenceError.

  • The binding exists from the block start.
  • Reading or writing it before the declaration throws.
  • The zone ends the moment the declaration runs.

Why it exists

The dead zone catches bugs that var silently hides. With var, an early read returns undefined, masking the mistake. With let, the same read fails loudly.

  • It makes use before declaration an explicit error.
  • const must be assigned at declaration, never before.
  • typeof on a dead zone variable also throws, unlike on an undeclared name.

This behavior enforces a discipline of declaring before using. The dead zone is not a runtime cost so much as a guardrail that turns a confusing undefined into a clear error you can fix.

Key idea

Let and const are hoisted but stay in the temporal dead zone until declared, so using them early throws instead of silently giving undefined.

Check yourself

Answer to earn rating on the learn ladder.

1. What happens if you read a let variable before its declaration?

2. How does var differ from let here?

3. What does typeof do on a temporal dead zone variable?