Tuesday, November 19, 2024
Google search engine
HomeLanguagesJavascriptJavaScript Object isSealed() Method

JavaScript Object isSealed() Method

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 neveropen'
};
 
// 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 neveropen'
};
 
// 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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments