Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JS Puzzles · Const

Temporal dead zone

The temporal dead zone is the interval from entering a block until execution initializes a let, const, or class binding. Accessing the binding during that interval throws a ReferenceError.

How it works

A const binding exists throughout its block, but it remains uninitialized from block entry until execution reaches its declaration. Accessing it during that interval throws a ReferenceError; the relevant boundary is execution order, not merely the declaration’s position in the source.

Syntax

const identifier = initializer;

Key points

  • The TDZ applies to const bindings as well as let and class bindings.
  • For const, the TDZ begins when its block starts and ends when its declaration runs.
  • The binding exists conceptually but has no usable value during this interval.
  • Reading the binding before initialization fails at runtime with ReferenceError.
  • Initialization occurs when control reaches the declaration, not merely when the script is parsed.

Common mistakes

  • typeof does not safely probe a lexical binding while it is in the temporal dead zone.
  • A function written before the declaration can still work if it is called only after initialization.

Example: Accessing const during its TDZ

{
  console.log(value); // ReferenceError
  const value = 42;
}

The access happens before initialization, so execution throws instead of producing a value.

When to use it

Diagnose ReferenceError failures

Reviewing code that reads a const before its declaration

Teach execution-order semantics

Explaining why declaration order and call order can differ

Avoid misleading existence checks

Auditing early typeof checks for lexical variables

Interview questions

QWhat is the temporal dead zone for const?

A const binding is in the TDZ from the beginning of its block until execution reaches its declaration and initialization. Reading it earlier throws a ReferenceError rather than returning undefined.

Follow-up: Does moving the declaration text always fix the problem? No: the access must execute after initialization, so control flow and calls matter.

QWhy can a function declared before const still access it?

The TDZ is based on execution order. A function may be defined before a const declaration and still read that binding successfully when called after the declaration has executed.

Follow-up: What happens if the function is called before initialization? Its read occurs inside the TDZ and throws a ReferenceError.

QHow does const differ from var before initialization?

var is initialized to undefined during hoisting, whereas const remains uninitialized until its declaration executes. Consequently, an early const access throws a ReferenceError.

Follow-up: Does typeof avoid this error? No; applying it to a lexical binding in the TDZ also throws a ReferenceError.

  • let
  • var
  • const declarations
  • block scope
  • ReferenceError

Source: let - JavaScript | MDN Web Docs. Checked 2026-10-15.