Object.seal()

seal(obj)
Returns: object · Added in vES5 · Updated March 16, 2026 · Object Methods
object seal restrict prevent modifications

The Object.seal() method seals an object, preventing new properties from being added to it and marking all existing properties as non-configurable. However, existing properties can still be modified (unlike freeze).

Syntax

Object.seal(obj)

Parameters

ParameterTypeDefaultDescription
objobjectThe object to seal.

Return Value

Returns the object that was passed in (not a copy).

Examples

Basic seal usage

const user = {
  name: 'Alice',
  age: 30
};

Object.seal(user);

// This works - changing existing property values is allowed
user.age = 31;
console.log(user.age);  // 31

// These fail - can't add or remove properties
user.email = 'alice@example.com';  // Ignored
delete user.name;                   // Ignored

Object.isSealed(user);  // true

Sealed objects let you modify existing values but prevent structural changes. This is useful when you want to lock down an object’s shape while allowing its data to evolve.

Freeze vs Seal Comparison

const frozen = Object.freeze({ value: 1 });
const sealed = Object.seal({ value: 1 });

// Frozen: can't change values
frozen.value = 2;
console.log(frozen.value);  // 1

// Seal: can change values
sealed.value = 2;
console.log(sealed.value);  // 2

// Both prevent extensions
frozen.newProp = 'x';
sealed.newProp = 'x';

console.log(frozen.newProp);  // undefined
console.log(sealed.newProp); // undefined

The key difference: freeze locks values too, while seal only locks structure.

Common Patterns

Protecting state objects in classes:

class Counter {
  constructor() {
    this._count = 0;
    Object.seal(this);
  }

  increment() {
    this._count++;  // Works - modifying value
    // Can't add new properties - sealed
  }
}

Caveats

Nested objects can still be modified:

const obj = {
  nested: { value: 1 }
};

Object.seal(obj);
obj.nested.value = 2;  // This works!

console.log(obj.nested.value);  // 2

Sealing doesn’t affect nested objects.

See Also