What's the difference between Object.freeze and Object.seal?
Quick answer
freeze blocks add, remove and edit (fully immutable, shallow); seal blocks add/remove but allows editing existing properties.
In detail
`Object.freeze(obj)` makes the object immutable at the top level — no new properties, no deletion, no reassignment (silently ignored, or throws in strict mode). `Object.seal(obj)` lets you change existing values but not add or delete keys. Both are shallow; nested objects stay mutable.
const f = Object.freeze({ x: 1 });
f.x = 9; f.x; // 1 (ignored)
const s = Object.seal({ x: 1 });
s.x = 9; s.x; // 9 (edit allowed)
s.y = 2; s.y; // undefined (add blocked)Why interviewers ask this: Tests immutability knowledge.
This is 1 of 118+ questions in the JavaScript Interview Kit
Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.
⚡ Get the JavaScript Interview Kit → ₹299