- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Temporal Dead Zone
JavaScript Scope & Hoisting
JavaScript Temporal Dead Zone
The JavaScript temporal dead zone is the gap between entering a scope and reaching a
letorconstdeclaration.
Inside that gap the variable exists but cannot be touched.
Reading it throws a ReferenceError, which is far more helpful than a silent undefined.
Example
Example
javascript
let ready = true;
console.log(ready);This works because the declaration comes first.
Moving the console.log above the declaration would throw an error.
What is the Temporal Dead Zone?
When JavaScript enters a scope, it registers every let and const in it.
Those variables are then held in an unusable state until their declaration line runs.
That unusable period is the temporal dead zone, usually shortened to TDZ.
