Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

JS Puzzles · Const

Object.seal

Object.seal(obj) prevents adding or removing properties and makes existing properties non-configurable. Writable existing values can still change.

How it works

Object.seal makes an object non-extensible and marks every existing property as non-configurable. The object keeps its current properties, so additions and removals are blocked, but existing data-property values may still change when writable.

Syntax

Object.seal(obj)

Parameters

NameTypeDescription
objobjectThe object to seal.

Returns

The same object that was passed to the method.

Key points

  • The object's set of properties becomes fixed: later code cannot add new properties or remove existing ones.
  • Every property already present receives a non-configurable descriptor, preventing descriptor changes and deletion.
  • Sealing does not make writable data values immutable.
  • Sealing preserves the existing prototype chain, although the object's own [[Prototype]] cannot be reassigned because extensions are disabled.
  • The return value is the sealed input object, enabling direct assignment when useful.

Common mistakes

  • Adding or deleting properties fails; in strict mode, the failed operation normally throws a TypeError, while non-strict code may fail silently.
  • Sealing is weaker than freezing: writable existing values remain mutable.
  • Object.seal does not affect class private elements.

Example: Seal an object without freezing its values

const settings = { theme: "dark" };
Object.seal(settings);

settings.theme = "light";
console.log(settings.theme); // "light"

settings.language = "en"; // ignored in non-strict mode
console.log(Object.isSealed(settings)); // true

Sealing keeps the existing property set fixed while still allowing writable property values to change.

When to use it

Lock an object’s property set

Protect a configuration object's shape after initialization while allowing selected writable values to update.

Expose a stable mutable API shape

Prevent consumers from deleting or adding public fields without making every value immutable.

Constrain shared object structure

Apply a shallow structural restriction before passing an object across a module boundary.

Interview questions

QWhat does Object.seal do?

Object.seal prevents extensions and makes all existing properties non-configurable. Therefore, properties cannot be added or removed, but writable existing values can still be changed.

Follow-up: How does it differ from Object.freeze()? Object.freeze also makes existing data properties non-writable, whereas Object.seal leaves writable values mutable.

QDoes Object.seal return a new object?

The method returns the same object reference that it receives; it does not create a sealed copy. The object itself becomes non-extensible and its existing properties become non-configurable.

Follow-up: How could you preserve the original object while sealing independently? Create a copy first, then pass that copy to Object.seal.

QHow can code verify that an object is sealed?

A sealed object is non-extensible and has no configurable own properties. Object.isSealed can be used to test that state, returning true when those conditions hold.

Follow-up: Is every non-extensible object sealed? No. Non-extensibility alone is insufficient; all existing properties must also be non-configurable.

  • Object.freeze()
  • Object.preventExtensions()
  • Object.isSealed()
  • Object.isExtensible()
  • property descriptors

Source: Property flags and descriptors. Checked 2026-10-15.