Does typeof escape the TDZ in JavaScript?
No. typeof on a let or const variable in the TDZ throws ReferenceError. This is different from typeof on an undeclared variable, which returns 'undefined' without throwing.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in The Temporal Dead Zone (TDZ): A Complete Explanation
The period between entering a scope where a let or const variable is declared and reaching the declaration line. Accessing the variable during this period throws ReferenceError: Cannot access 'x' before initialization.
var is initialized to undefined during the memory phase, so it is usable early. let and const are not initialized until the declaration line, so the gap (TDZ) throws an error. This forces declare-before-use and catches bugs.
Yes. Default parameters are evaluated left to right. A parameter that references a later parameter throws ReferenceError because that later parameter is still in the TDZ.
Still have questions?
Browse all our FAQs or reach out to our support team
