Loading...
Loading...
By continuing to use the platform, you accept the terms of the Privacy Policy and the use of cookies.
TDZ (Temporal Dead Zone) is the time period between the start of a variable's scope (e.g., if block, for, function, etc.) and its actual initialization, during which the variable cannot be accessed.
This zone occurs when using let or const.
console.log(x); // ❌ ReferenceError: Cannot access 'x' before initialization
let x = 10;
Although variable x is declared, you get an error because you accessed it before initialization — you're in the temporal dead zone.
letconstclass| Variable Type | Hoisted | Initialized | TDZ Exists |
|---|---|---|---|
var | Yes | undefined | No |
let | Yes | No | Yes |
const | Yes | No | Yes |
Important:
TDZ is the reason why let and const are safer than var: you cannot use variables before they're declared, and this prevents errors.