Object.isSealed()

ES5+

Determines if an object is sealed.

Syntax

Object.isSealed(obj)

Parameters

obj Object

The object to check

Return Value

boolean

true if the object is sealed, otherwise false

Examples

JavaScript
const obj = { a: 1 };
console.log(Object.isSealed(obj));
Object.seal(obj);
console.log(Object.isSealed(obj));
Output:
// false true

📌 When to Use

Use Object.isSealed() to verify that an object has been properly sealed before relying on its fixed structure, in validation logic to ensure data integrity, or when debugging to confirm object state in your application.

⚠️ Common Mistakes

Confusing isSealed with isFrozen - a frozen object is always sealed, but isSealed returns true for both sealed-only and frozen objects.

Assuming an empty object is not sealed - empty objects without properties are considered sealed by default.

✅ Best Practices

Use in combination with isFrozen to determine the exact mutability level: sealed but not frozen means values can change.

Create a utility to check object mutability state: { sealed: Object.isSealed(obj), frozen: Object.isFrozen(obj), extensible: Object.isExtensible(obj) }

⚡ Performance Notes

Object.isSealed() is an O(1) operation that checks internal object flags. It does not iterate over properties. Very fast and safe to use in any context, including tight loops and hot paths.

🌍 Real World Example

Object Mutability Inspector

Create a diagnostic utility that reports the complete mutability state of any object for debugging purposes.

function inspectMutability(obj, name = 'Object') {
  const isSealed = Object.isSealed(obj);
  const isFrozen = Object.isFrozen(obj);
  const isExtensible = Object.isExtensible(obj);

  let status;
  if (isFrozen) {
    status = 'FROZEN (completely immutable)';
  } else if (isSealed) {
    status = 'SEALED (fixed structure, mutable values)';
  } else if (!isExtensible) {
    status = 'NON-EXTENSIBLE (no new props, can delete/modify)';
  } else {
    status = 'MUTABLE (fully changeable)';
  }

  return {
    name,
    isSealed,
    isFrozen,
    isExtensible,
    status,
    propertyCount: Object.keys(obj).length
  };
}

// Test different object states
const normal = { a: 1 };
const sealed = Object.seal({ b: 2 });
const frozen = Object.freeze({ c: 3 });

console.log(inspectMutability(normal, 'Normal'));
// { name: 'Normal', isSealed: false, isFrozen: false, isExtensible: true, status: 'MUTABLE', propertyCount: 1 }

console.log(inspectMutability(sealed, 'Sealed'));
// { name: 'Sealed', isSealed: true, isFrozen: false, isExtensible: false, status: 'SEALED', propertyCount: 1 }

console.log(inspectMutability(frozen, 'Frozen'));
// { name: 'Frozen', isSealed: true, isFrozen: true, isExtensible: false, status: 'FROZEN', propertyCount: 1 }

Related Methods