JavaScript: Object.seal

By Xah Lee. Date: . Last updated: .

Object.seal( obj)

  1. Set the obj's extension attribute to false.
  2. Set ALL of the obj's own property's “configurable” attributes to false. (so properties cannot be deleted.)
  3. Return the modified object obj.

When a object is sealed, properties cannot be added to it, and properties cannot be deleted. (however, the parent (prototype) object may still have properties added or deleted.)

[see Prevent Adding Property]

// seal a object.

const x3 = {"p1":1, "p2":2};

console.log(Object.getOwnPropertyDescriptor(x3, "p1"));
// { value: 1, writable: true, enumerable: true, configurable: true }

Object.seal(x3);

// configurable attribute for property p1 is now false
console.log(Object.getOwnPropertyDescriptor(x3, "p1"));
// { value: 1, writable: true, enumerable: true, configurable: false }

// configurable attribute for property p2 is now false
console.log(Object.getOwnPropertyDescriptor(x3, "p2"));
// { value: 2, writable: true, enumerable: true, configurable: false }

// Extensible attribute is now false
console.log(Object.isExtensible(x3)); // false
JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Object Object

prototype