Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

JavaScript Dictionary

  1. Home
  2. JavaScript Dictionary
  3. Object.freeze() / seal()

Object.freeze() / seal() Since: ES5(ECMAScript 2009)

Prevents modification of an object's properties. Object.freeze() fully freezes an object, while Object.seal() allows value changes but nothing else.

Syntax

// Freezes an object. Adding, deleting, and modifying properties are all prohibited.
Object.freeze(object)

// Seals an object. Adding and deleting properties are prohibited, but modifying values is allowed.
Object.seal(object)

// Returns whether the object is frozen.
Object.isFrozen(object)

// Returns whether the object is sealed.
Object.isSealed(object)

Method List

MethodDescription
Object.freeze(object)Freezes an object, prohibiting all additions, deletions, and value changes to its properties. Returns the frozen object.
Object.seal(object)Seals an object, prohibiting property additions and deletions. Existing property values can still be modified.
Object.isFrozen(object)Returns true if the object is frozen, or false otherwise.
Object.isSealed(object)Returns true if the object is sealed, or false otherwise.

Sample Code

// Freeze an object with Object.freeze.
var config = { apiUrl: "https://api.example.com", timeout: 3000 };
Object.freeze(config);

config.timeout = 5000;       // Modification is silently ignored.
config.retryCount = 3;       // Addition is silently ignored.
delete config.apiUrl;        // Deletion is silently ignored.
console.log(config.timeout); // Outputs 3000 (unchanged).
console.log(config.retryCount); // Outputs undefined.

// Seal an object with Object.seal.
var settings = { theme: "dark", lang: "ja" };
Object.seal(settings);

settings.theme = "light";    // Value modification is allowed.
settings.fontSize = 14;      // Addition is silently ignored.
delete settings.lang;        // Deletion is silently ignored.
console.log(settings.theme); // Outputs "light".
console.log(settings.fontSize); // Outputs undefined.

// Check frozen/sealed status.
console.log(Object.isFrozen(config));   // Outputs true.
console.log(Object.isSealed(config));   // A frozen object is also sealed, so outputs true.
console.log(Object.isSealed(settings)); // Outputs true.
console.log(Object.isFrozen(settings)); // Outputs false.

Differences Between freeze and seal

OperationObject.freeze()Object.seal()
Add propertyNot allowed.Not allowed.
Delete propertyNot allowed.Not allowed.
Modify valueNot allowed.Allowed.

Overview

Object.freeze() and Object.seal() are methods that restrict modifications to an object. Object.freeze() is the strictest option, prohibiting all property additions, deletions, and value changes. Object.seal() only prohibits additions and deletions, while still allowing value changes.

Note that both methods apply only a shallow restriction. Nested objects are not frozen or sealed, so properties on inner objects can still be modified. To fully freeze an object including nested ones, you need to apply Object.freeze() recursively.

Attempts to modify a frozen or sealed object are silently ignored with no error. However, in strict mode ("use strict"), a TypeError is thrown, making unintended modifications easier to detect. These methods are effective for data that must not change during program execution, such as configuration objects and constants.

Browser Compatibility

Chrome Chrome
49+
5 or earlier ×
Firefox Firefox
57+
3.5 or earlier ×
Safari Safari
18+
5 or earlier ×
Edge Edge
80+
11 or earlier ×
IE IE
11+
8 or earlier ×
Opera Opera
48+
11 or earlier ×
iOS Safari iOS Safari
18+
4 or earlier ×
Android Browser Android Browser
37+
4 or earlier ×
Chrome Android Chrome Android
36+
17 or earlier ×
Firefox Android Firefox Android
79+
3 or earlier ×

If you find any errors or copyright issues, please .