Question presented to candidate: "What is the temporal dead zone, and how is it different from a variable simply being undefined?"
What a strong answer should cover:
- The temporal dead zone (TDZ) is the span of code between entering a scope and the line where a let or const binding is actually declared, during which that binding exists but has not been initialized yet.
- Accessing a variable while it is in its TDZ throws a real ReferenceError -- it is not the same as the variable being undefined.
- var has no TDZ -- it is hoisted AND initialized to undefined immediately, so accessing it early just silently gives undefined instead of throwing.
- Even typeof is not TDZ-safe -- typeof on a name that is declared later in the current scope with let/const throws, unlike typeof on a name that is not declared anywhere at all, which safely returns "undefined".
- The TDZ is scope-local: it belongs to a specific binding in a specific scope, so an inner let of the same name as an outer variable creates its own TDZ that shadows the outer one, even before the inner declaration's line.
- class declarations have a TDZ too, just like let and const -- they are not hoisted the way function declarations are.
Code / implementation expected: Yes -- a runnable snippet showing let/const throwing ReferenceError before their declaration line, contrasted with var's hoisted-undefined behavior.