Object.seal
Forbids adding and removing properties but lets existing ones change.
Available since: ES5
Syntax
Object.seal(obj)Parameters
| Parameter | Type | Description |
|---|---|---|
| obj | object | The object to seal. |
Return value
objectThe same object, now sealed.
Examples
Changing works, adding and removing do not:
const user = Object.seal({ name: 'Anna' });
user.name = 'Oleg';
user.age = 30;
delete user.name;
console.log(user);Output:
{
"name": "Oleg"
}Notes
The difference from Object.freeze(): a sealed object can be modified, only its shape — the set of properties — is fixed.
See also
- Object.freeze — Prevents any changes to an object.
- Object.isFrozen — Checks whether an object is frozen.
In the tutorial
- Immutability — Mutable and immutable data in JavaScript: object references, copying with spread, the toSorted and with methods, Object.freeze and structuredClone.