Facebook Pixel

What error does accessing a let variable in the TDZ throw?

ReferenceError: Cannot access 'x' before initialization. The message is different from 'not defined', but it is still a ReferenceError because the variable reference cannot be resolved to a value.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in SyntaxError vs ReferenceError vs TypeError in JavaScript

SyntaxError is caught at parse time (malformed code, const without initializer, re-declaration). ReferenceError is at runtime (variable does not exist or is in TDZ). TypeError is at runtime (value is wrong type for the operation, reassigning const).

Because the engine catches it during parsing, before any code runs. 'const x;' is malformed syntax (const requires an initializer), so it is a SyntaxError, not a runtime ReferenceError.

Because the variable exists (no ReferenceError), but the operation (assignment) is not allowed for a const. The value's type (const binding) does not support reassignment, so it is a TypeError.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.