Skip to content
Tutorials Center
My learning

Topics

JavaScript Reference ยท Object

Object.seal()

Reference for JavaScript Object.seal(): lock an object's set of properties so none can be added or removed while values stay writable.

Object.seal() locks the shape of an object. After sealing, you cannot add new properties, delete existing ones, or reconfigure them (for example, turn a data property into an accessor). Values of writable properties can still change.

Think of it as Object.preventExtensions() plus "every existing property becomes non-configurable". It sits between that call and Object.freeze(), which also makes values read-only.

JavaScript
Object.seal(obj);
Object.isSealed(obj); // true

Try it

JS Values change, shape does not

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS Strict mode reports the failures

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Syntax

JavaScript
Object.seal(obj)
Name Description
obj The object to seal.

Return value: the same object that was passed in. Primitive arguments are returned as they are.

Exceptions: none for the call itself. Operations that violate the seal throw a TypeError in strict mode and fail silently otherwise.

Usage notes

  • Permanent and shallow. A sealed object cannot be unsealed, and nested objects are not sealed. Seal them separately if you need a deep lock.
  • Writable stays writable. Sealing sets configurable: false on every own property but leaves writable alone. A writable property can still be assigned; a writable data property can also be switched to read-only with Object.defineProperty(), which is the one allowed change.
  • Arrays can be sealed. Elements can be replaced, but push() and pop() fail (they throw a TypeError because they try to add or remove elements).
  • Sealed is also non-extensible. Object.isExtensible() returns false.
  • Frozen objects are sealed. Object.isSealed() is true for any frozen object.
  • When to use it: a fixed record whose fields should keep updating, such as a state object with a known list of keys. For a constant, use Object.freeze().
  • Performance: sealing is cheap, and engines can sometimes optimize objects whose shape cannot change, but do not rely on that.

Browser support

Object.seal() is available in every browser and JavaScript runtime.