JavaScript (ES2026) reference · Object Methods

JavaScript Object.seal() Method

Prevent adding or removing properties while still allowing existing properties to be changed.

JavaScript (ES2026) Since ES5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Object.seal(obj)

Parameters

ParameterDescription
obj The object to inspect or change.

Return value

The same object, now sealed.

Examples

Change, but not addTry it yourself
"use strict";
const point = Object.seal({ x: 1, y: 2 });
point.x = 10;
try { point.z = 3; } catch (e) { console.log(e.constructor.name); }
console.log(point);

Output

TypeError
{ x: 10, y: 2 }
Deleting failsTry it yourself
const p = Object.seal({ a: 1 });
try {
  delete p.a; // examples run as modules, which are strict mode
} catch (e) {
  console.log(e.constructor.name);
}
console.log(p);

Output

TypeError
{ a: 1 }

Version history

VersionChange
JavaScript ES5Added

Was this page helpful?