JavaScript Object.seal() Method

Definition
Object.seal(obj) seals an object: you cannot add or remove properties, and every property becomes non-configurable.
Writable values can still be updated. For a full lock that also blocks value changes, use Object.freeze. Check with Object.isSealed.
Syntax
Call Object.seal() like this. Start with this line.
| Call | What it does |
|---|
Object.seal(obj) | Seals obj and returns it. |
Object.isSealed(obj) | Returns true after sealing. |
delete obj.key | Fails after seal (ignored in non-strict mode). |
Returns the same object. Sealing cannot be undone.
Library declarations
Parameters
| Parameter | Description |
|---|
| obj | Required. The object to seal. |
Return Value
| Return Value | Description |
|---|
| object | The same object, now sealed. |
JavaScript Examples
Seal and Update a Value
Seal a settings object, change a value, and try to add a key.
var settings = { theme: "dark", lang: "en" };
Object.seal(settings);
settings.theme = "light";
settings.font = "large";
delete settings.lang;
console.log(settings);
console.log(Object.isSealed(settings));
{ theme: 'light', lang: 'en' }
trueHow It Works
- Value update works.
theme changes to "light" because it is still writable. - Add fails.
font is not added on a sealed object. - Delete fails.
lang stays. Seal blocks removing keys.
Seal Allows Changes; Freeze Does Not
Compare the same assignment on sealed and frozen objects.
var sealed = { n: 1 };
Object.seal(sealed);
sealed.n = 5;
console.log(sealed.n);
var frozen = { n: 1 };
Object.freeze(frozen);
frozen.n = 5;
console.log(frozen.n);
How It Works
- Sealed write. The sealed object accepts the new value
5. - Frozen write. The frozen object keeps
1 in non-strict mode. - Choose by need. Use seal for fixed keys with live data. Use freeze for read-only data.
Confirm with isSealed and isExtensible
After sealing, both sealed and non-extensible checks should agree.
var profile = { name: "Ada" };
Object.seal(profile);
console.log(Object.isSealed(profile));
console.log(Object.isExtensible(profile));
console.log(Object.isFrozen(profile));
How It Works
- Sealed.
isSealed is true. - Not extensible. Sealing also turns off extensibility.
- Not frozen. Values can still change, so
isFrozen is false.
Compatibility
Browser & Runtime Support
Object.seal() comes from ES5 and is supported in all modern browsers and Node.js.
✓ ES5 · Baseline
Object.seal()
Available in every current browser and server runtime. Pair with Object.isSealed().
100% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full supportObject.seal Excellent
Bottom line: Safe for production. Use when object shape must stay fixed but property values may still update.
Frequently Asked Questions
It stops adding and removing properties. Existing writable values can still be changed.
No. Use Object.freeze() if values must not change.
No. Sealing is permanent for that object. Copy properties into a new object if you need mutability again.
Yes. Object.isExtensible returns false after seal.
Delete fails. In non-strict mode it is ignored; in strict mode it throws TypeError.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
8 people found this page helpful