JavaScript .isSealed()
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.
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:
falsetrue
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:
falsetrue
Note: If
typeorpriceproperty is configurable, then thefruitsobject will not be sealed.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve 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