Junior — Middle
Mida tähendab termin TDZ ja kuidas see mõjutab JavaScripti koodi täitmist?
sobes.tech AI
Vastus AI-lt
The Temporal Dead Zone (TDZ) is the period between the declaration of a variable with let or const and its actual assignment, during which access to the variable results in an error.
Unlike var, variables declared with let and const are not hoisted with initialization and remain in the TDZ until the declaration is processed. Attempting to access a variable in the TDZ will throw a ReferenceError.
Example:
console.log(a); // ReferenceError: Cannot access 'a' before initialization
let a = 10;
The TDZ helps prevent errors related to using variables before they are declared, making the code more predictable and safer.