Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Object.seal — sealing an object

Object.seal prevents adding and deleting an object's own properties without making the object immutable. On ordinary objects, existing writable data properties can still receive new values, and nested objects are not automatically sealed.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

Object.seal(obj)

Object.seal(obj) modifies the supplied object and returns that same object without copying it. It prevents extensions and sets configurable: false on every own property, including non-enumerable and Symbol-keyed properties. You can no longer add or delete own properties, change their enumerability, or convert data properties into accessors or vice versa.

Sealing does not mean immutability. On an ordinary object, existing data properties with writable: true still accept new values, and you can change writable from true to false, but not back. A sealed module namespace object reports writable: true in its export property descriptors, but rejects both assignment to those properties and attempts to set their writable attribute to false. Existing setters can still operate. The operation is shallow: nested objects are not automatically sealed.

Object.preventExtensions prevents adding own properties but does not itself make existing properties non-configurable. On an ordinary object, Object.freeze additionally sets writable: false on own data properties; it is also shallow. Check sealing with Object.isSealed.

In strict mode, a disallowed assignment of a new property or deletion of an existing property using delete throws TypeError; outside strict mode, these operations generally fail silently. Object.seal can throw if sealing fails, for example with some Proxy objects. In modern ECMAScript, a non-object argument is returned unchanged.

Examples

"use strict";

const settings = { volume: 2, theme: { dark: false } };
const result = Object.seal(settings);
settings.volume = 3;
settings.theme.dark = true;

console.log(result === settings);
console.log(Object.isSealed(settings));
console.log(settings.volume, settings.theme.dark);

try {
  settings.extra = 1;
} catch (error) {
  console.log(error instanceof TypeError);
}

console.log(Reflect.deleteProperty(settings, "volume"));
console.log(Object.isSealed(settings.theme));

Result

true
true
3 true
true
false
false

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources