What is the temporal dead zone (TDZ)?

Answer

The Temporal Dead Zone (TDZ) is the period between the start of a block scope and the point where a let or const declaration is encountered. During the TDZ, the variable exists in scope (it has been hoisted) but has not been initialized — accessing it throws a ReferenceError. Example: console.log(x); // ReferenceError: Cannot access "x" before initialization\nlet x = 5;. Unlike var which initializes to undefined during hoisting, let and const are hoisted to the top of the block but remain in the TDZ until their declaration is reached. This was an intentional design decision to eliminate "use before declaration" bugs that were common with var. The TDZ also applies to function parameters when using default values: function f(a = b, b = 1) { }a accessing b before b is initialized throws ReferenceError.