JavaScript - Temporal Dead Zone (TDZ)
Overview
Estimated time: 10–15 minutes
The Temporal Dead Zone (TDZ) is the period between entering scope and variable declaration with let
or const
.
Learning Objectives
- Understand what the TDZ is and why it exists.
- Recognize errors caused by accessing variables in the TDZ.
Prerequisites
TDZ Example
console.log(a); // ReferenceError
let a = 3;
Common Pitfalls
- TDZ only applies to
let
andconst
, notvar
.
Summary
The TDZ helps catch bugs by preventing access to variables before declaration.