Skip to solution
hardFrontend

What is the temporal dead zone?

465 views
01

Understand the problem

Question presented to candidate: "What is the temporal dead zone, and how is it different from a variable simply being undefined?"

What a strong answer should cover:

  • The temporal dead zone (TDZ) is the span of code between entering a scope and the line where a let or const binding is actually declared, during which that binding exists but has not been initialized yet.
  • Accessing a variable while it is in its TDZ throws a real ReferenceError -- it is not the same as the variable being undefined.
  • var has no TDZ -- it is hoisted AND initialized to undefined immediately, so accessing it early just silently gives undefined instead of throwing.
  • Even typeof is not TDZ-safe -- typeof on a name that is declared later in the current scope with let/const throws, unlike typeof on a name that is not declared anywhere at all, which safely returns "undefined".
  • The TDZ is scope-local: it belongs to a specific binding in a specific scope, so an inner let of the same name as an outer variable creates its own TDZ that shadows the outer one, even before the inner declaration's line.
  • class declarations have a TDZ too, just like let and const -- they are not hoisted the way function declarations are.

Code / implementation expected: Yes -- a runnable snippet showing let/const throwing ReferenceError before their declaration line, contrasted with var's hoisted-undefined behavior.

temporal-dead-zone
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript fundamentals interview questions. Difficulty: Easy-Medium

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. Every result below was actually run on Node.js v24.19.0 — the printed outpu

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSlet/const throw in the TDZ; var silently returns undefined (run directly)
JStypeof is not TDZ-safe; class has a TDZ too (run directly)
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 148 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track