.isSealed()
hP318894158012 total contributions
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
type
orprice
property is configurable, then thefruits
object will not be sealed.
Looking to contribute?
- 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.