Hoisting and Execution Context
What is the temporal dead zone (TDZ) in JavaScript?
The temporal dead zone (TDZ) is the period between entering a scope where a variable is defined with `let` or `const` and the point where the variable declaration is actually reached during execution. During this zone, the variable exists but cannot be accessed or used in any way. Any attempt to access the variable within the TDZ will result in a ReferenceError. For example: ```javascript { // TDZ for x starts here console.log(x); // ReferenceError: Cannot access 'x' before initialization let x = 5; // TDZ ends for x console.log(x); // 5 (works fine) } ``` The TDZ was introduced with the `let` and `const` declarations in ES6 to help catch programming errors. Unlike variables declared with `var` (which are initialized with `undefined` when hoisted), `let` and `const` variables remain uninitialized within the TDZ. This behavior makes it easier to spot potential issues with variable access before proper initialization, which helps write safer code with fewer unexpected behaviors.