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.
Common let and const Mistakes in JavaScript
What is the most common mistake with const in JavaScript?
The answer
More FAQs in Common let and const Mistakes 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.
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
Want to upskill yourself?
Your learning library
Small steps. Big possibilities.
Find your next course. Build something great.