JavaScript Internals (521 Qs)•Part 4: Prototypes, Object Methods & Event Loop (174 - 253)
What are the applications of the seal method
Below are the main applications of Object.seal() method,
- It is used for sealing objects and arrays.
- It is used to make properties of an object non-configurable.
Practical Code Example
javascript
// Applications of Object.seal():
// When you want a fixed schema (no properties added or removed), but property values can be updated:
const record = { id: 101, status: 'pending' };
Object.seal(record);
record.status = 'approved'; // Allowed!
record.newField = 123; // Blocked!
delete record.id; // Blocked!
console.log(record.status); // 'approved'