Why does const without an initializer throw SyntaxError in JavaScript?
Because const requires a value at declaration (const x = 5). The engine catches the missing initializer at parse time, before any code runs, so it is a SyntaxError not a runtime error.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in Common let and const Mistakes in JavaScript
Assuming it makes objects and arrays immutable. const only prevents reassignment of the variable binding. You can still mutate the object's properties. Use Object.freeze for immutability.
Because i++ reassigns i, and const does not allow reassignment. It throws TypeError: Assignment to constant variable. Use let for classic for loop counters, const for for...of and for...in.
Because all cases in a switch share one block scope (unless wrapped in braces). A let in two cases is a re-declaration in the same scope. Fix by wrapping each case in its own block with braces.
Still have questions?
Browse all our FAQs or reach out to our support team
