Is Object.freeze shallow or deep in JavaScript?
Shallow. Object.freeze prevents changes to the top-level object's properties, but nested objects can still be mutated. For deep immutability, you need a recursive deepFreeze function.
Verify This Answer
Cross-check this information using these trusted sources:
More FAQs in const with Objects and Arrays in JavaScript
No. const prevents reassignment of the variable, but you can still mutate the object's properties (add, change, delete). Use Object.freeze for immutability.
const prevents reassignment of the variable binding. Object.freeze prevents mutation of the object itself (no property changes, additions, or deletions). They work at different levels: const is about the variable, freeze is about the value.
Yes. const prevents reassigning the array variable, but you can still mutate the array with push, pop, splice, and index assignment. Use Object.freeze (or Object.freeze(arr)) to prevent mutations.
Still have questions?
Browse all our FAQs or reach out to our support team
