Open In App

JavaScript Object isSealed() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

JavaScript object.isSealed() method is used to determine if an object is sealed or not. An object is sealed if all of the below-mentioned conditions hold true :

  • If it is not extensible.
  • If all of its properties are non-configurable.
  • If it is not removable (but not necessarily non-writable).

Object.isSealed() takes the object as an argument that has to be checked and returns a boolean representing whether the object is sealed or not. 

Syntax:

Object.isSealed(obj)

Parameters: 

  • obj: It is the object which has to be checked. 

Return Value: Object.isSealed() returns a boolean representing whether the object is sealed or not.

Examples of the above function are provided below. 

Example 1: In the above example the object has not been sealed using the Object.seal() method, therefore, it returns false when it is checked using Object.isSealed() method.

Javascript




// creating an object constructor
// and assigning values to it
const object = {
    property: 'hi geeksforgeeks'
};
 
// checking whether the object
// is sealed or not
console.log(Object.isSealed(object));


Output:

false

Example 2: In the above example the object has been sealed using the Object.seal() method, therefore, it returns true when it is checked using Object.isSealed() method.

Javascript




// creating an object constructor
// and assigning values to it
const object = {
    property: 'hi geeksforgeeks'
};
 
// Using seal() method to seal the object
Object.seal(object);
 
// checking whether the
// object is frozen or not
console.log(Object.isSealed(object));


Output:

true

Applications:

  • Object.isSealed() is used for checking whether an object is sealed or not.

Exceptions :

  • It causes a TypeError if the argument passed is not an object.
  • If an object is not passed as an argument to the method, then it treats it as a sealed object and returns true.

We have a complete list of Javascript Object methods, to check those please go through this JavaScript Object Complete Reference article.

Supported Browsers:

  • Chrome 6 and above
  • Edge 12 and above
  • Firefox 4 and above
  • Internet Explorer 9 and above
  • Opera 12 and above
  • Safari 5.1 and above

Last Updated : 19 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads