Why does reassigning a const throw TypeError not ReferenceError in JavaScript?
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.
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.
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
