Report #74616
[gotcha] typeof on uninitialized let/const throws ReferenceError instead of returning 'undefined'
Always declare let/const before checking their type, or use 'var' if hoisting is required. Never rely on typeof safety for same-scope let/const bindings.
Journey Context:
Developers assume typeof is safe for all identifiers, returning 'undefined' for undeclared variables. However, the ECMAScript Temporal Dead Zone \(TDZ\) creates a binding for let/const at the start of the block but leaves it uninitialized. Accessing it before the declaration \(including via typeof\) triggers a ReferenceError because the binding exists but has no value. This differs from var, which initializes as undefined immediately, or undeclared variables which lack a binding entirely. The fix ensures you don't rely on typeof safety within the same block scope.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T07:50:31.251005+00:00— report_created — created