temporal dead zone

JSvariable ⟩ temporal dead zone

🈯 acronym: TDZ

A let/ const / class is said to be in a "temporal dead zone" from the start of the block until code execution reaches the line where the variable is (declared and) initialized.

TDZ

  • the time window where a const/let variable exists but is still uninitialized, and therefore cannot be accessed in any way.

the term "temporal" is used because the zone depends on the order of execution (time) rather than the order of place in which the code is written (position).

{
                                        // TDZ (for `a`) starts
    const f = () => console.log(a);     // - OK: `a` hasn't been actually referenced.
    let a = 3;                          // TDZ (for `a`) ends.

    f();                                // OK: `a` called outside TDZ.
}

Last updated