πŸ”΄ HardClosures & ScopeπŸ’» Output Question

Temporal Dead Zone with let

πŸ’‘

Hint

TDZ begins at block entry, not at the declaration line. A local let shadows the outer scope immediately, blocking access to both until the declaration.

What does this output?

let x = 'global';

function test() {
  console.log(x);
  let x = 'local';
  console.log(x);
}

try {
  test();
} catch (e) {
  console.log(e.constructor.name);
}

Correct Output

ReferenceError

Why this output?

Explanation: Even though global x exists, the let x declaration in test() "shadows" the global one starting from the top of the block. Accessing x before the let declaration = TDZ = ReferenceError.

Key Insight: TDZ begins at block entry, not at the declaration line. A local let shadows the outer scope immediately, blocking access to both until the declaration.

More Closures & Scope Output Questions

🟒 EasyClassic var in loop closureβ†’πŸŸ’ Easylet in loop closure (fix)β†’πŸŸ‘ MediumClosure counterβ†’πŸŸ‘ MediumIIFE closureβ†’

Practice predicting output live β†’

66 output questions with instant feedback

πŸ’» Try Output Quiz