The Object.isSealed()
method determines if an object is sealed or not. An object is sealed if:
Note:
- An object is sealed using the
Object.seal()
orObject.freeze()
methods.- A sealed object cannot be unsealed.
The isSealed()
method is declared as follows:
Object.isSealed(obj)
obj
: The object that is to be checked to determine whether it is sealed.Note: If
obj
is not an object,TypeError
is thrown.
The isSealed()
method returns a boolean value depending on whether or not the object obj
is sealed.
true
: if obj
is sealed.false
: if obj
is not sealed.Consider the code snippet below, which demonstrates the use of the isSealed()
function.
var obj = { property1:'Foo'}console.log("obj is sealed: ", Object.isSealed(obj))Object.seal(obj)console.log("obj is sealed: ", Object.isSealed(obj))
An object obj
is created in line 1. Calling the isSealed()
method on obj
returns false
, as the object is not sealed. After obj
is sealed in line 5, the isSealed()
method returns true
.
Free Resources