JavaScript (ES2026) reference · Object Methods
JavaScript Object.seal() Method
Prevent adding or removing properties while still allowing existing properties to be changed.
JavaScript (ES2026) Since ES5
Syntax
Object.seal(obj)
Parameters
| Parameter | Description |
|---|---|
obj |
The object to inspect or change. |
Return value
The same object, now sealed.
Examples
"use strict";
const point = Object.seal({ x: 1, y: 2 });
point.x = 10;
try { point.z = 3; } catch (e) { console.log(e.constructor.name); }
console.log(point);
Output
TypeError
{ x: 10, y: 2 }const p = Object.seal({ a: 1 });
try {
delete p.a; // examples run as modules, which are strict mode
} catch (e) {
console.log(e.constructor.name);
}
console.log(p);
Output
TypeError
{ a: 1 }Version history
| Version | Change |
|---|---|
| JavaScript ES5 | Added |
Related
Object.isSealed()· Return true if an object is sealed: properties can't be added or removed, but existing ones may still change.Object.freeze()· Make an object immutable: no properties can be added, removed or changed. The freeze is shallow.- JavaScript Objects · tutorial