Example 1 — After init
Safe to use.
JavaScript
let a = 1;
console.log(a);How It Works
- Initialization completed.
The temporal dead zone (TDZ) is the time from entering a scope until a let or const finishes initializing. Reading the binding in that window throws ReferenceError.
try {
console.log(a);
let a = 1;
} catch (e) {
console.log(e.name);
}Safe to use.
let a = 1;
console.log(a);Unlike undeclared vars.
try { typeof x; let x = 1; } catch (e) { console.log(e.name); }Must initialize on the line.
const n = 3;
console.log(n);CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful