Skip to content
Related Articles
Open in App
Not now

Related Articles

Object.isSealed() In JavaScript

Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 22 Dec, 2022
Improve Article
Save Article

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




<script>
    // 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));
</script>

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




<script>
    // 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));
</script>

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

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!