JavaScript Internals (521 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)
What are the differences between the freeze and seal methods
If an object is frozen using the Object.freeze() method then its properties become immutable and no changes can be made in them whereas if an object is sealed using the Object.seal() method then the changes can be made in the existing properties of the object.
Practical Code Example
javascript
// Object.freeze() vs Object.seal():
// freeze: Read-only. Cannot add, cannot delete, CANNOT modify existing values.
// seal: Fixed keys. Cannot add, cannot delete, CAN modify existing values.
const frozen = Object.freeze({ count: 1 });
frozen.count = 2; // Fails! Value remains 1
const sealed = Object.seal({ count: 1 });
sealed.count = 2; // Succeeds! Value updated to 2