Why does const without an initializer throw SyntaxError not ReferenceError?
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.
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 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.
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.
Still have questions?
Browse all our FAQs or reach out to our support team
