Does const make arrays and objects immutable in JavaScript?
No. const prevents reassignment of the variable, but you can still mutate the array or object (push, pop, property changes). Use Object.freeze() or immutable libraries for true immutability.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in var vs let vs const: When to Use Each in JavaScript
Use const by default (most variables should not be reassigned). Use let when you need to reassign (counters, changing values). Avoid var in modern code; it is function-scoped and hoisted with undefined, which causes bugs.
const. Each iteration of for...of creates a fresh binding, and the loop variable does not change within an iteration. Use let only for classic for loops where the counter increments.
var is function-scoped (leaks out of blocks), hoisted with undefined (causes hoisting bugs), and allows silent re-declaration (hides typos). let and const are block-scoped, respect the TDZ, and throw on re-declaration.
Still have questions?
Browse all our FAQs or reach out to our support team
