JavaScript .isSealed()

hP3188941580's avatar
Published Dec 19, 2023
Contribute to Docs

The .isSealed() method is used to check if an object is sealed. An object is sealed when it is non-extensible, and all of its properties are non-configurable.

  • Learn how to build back-end web APIs using Express.js, Node.js, SQL, and a Node.js-SQLite database library.
    • Includes 8 Courses
    • With Certificate
    • Beginner Friendly.
      30 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours

Syntax

Object.isSealed(object_name)
  • object_name: The name of the object to be checked.

Examples

Example 1

The following code will determine if the fruits object is sealed or not by using Object.seal() and Object.isSealed() methods:

let fruits = {
type: 'watermelon',
price: '$0.99 per pound',
};
console.log(Object.isSealed(fruits));
Object.seal(fruits);
console.log(Object.isSealed(fruits));

The above code will return the following output:

false
true

Example 2

The following code will determine if the fruits object is sealed or not by using Object.preventExtensions() and Object.defineProperties() methods:

let fruits = {
type: 'watermelon',
price: '$0.99 per pound',
};
console.log(Object.isSealed(fruits));
Object.preventExtensions(fruits);
Object.defineProperties(fruits, {
type: {
configurable: false,
writable: true,
},
price: {
configurable: false,
writable: true,
},
});
console.log(Object.isSealed(fruits));

The above code will return the following output:

false
true

Note: If type or price property is configurable, then the fruits object will not be sealed.

All contributors

Contribute to Docs

Learn JavaScript on Codecademy

  • Learn how to build back-end web APIs using Express.js, Node.js, SQL, and a Node.js-SQLite database library.
    • Includes 8 Courses
    • With Certificate
    • Beginner Friendly.
      30 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours