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

JavaScript Object isExtensible() Method

The Object.preventExtensions() method in JavaScript is a standard built-in object which checks whether an object is extensible or not(i.e. if we can add new properties to the object or not).

Syntax: 

Object.isExtensible( obj )

Parameters: This method accepts a single parameter as mentioned above and described below: 

  • obj: This parameter holds the object which should be checked for extensibility.

Return value: This method returns a Boolean value indicating if the given object is extensible or not.

The below examples illustrate the Object.isExtensible() Method in JavaScript:

Example 1: In this example, we will check if new properties can be added to an object or not using the Object.isExtensible() Method in JavaScript. The output is a Boolean value.

javascript




const neveropen1 = {};
console.log(Object.isExtensible(neveropen1));
Object.preventExtensions(neveropen1);
console.log(Object.isExtensible(neveropen1));
  
const neveropen2 = {};
Object.preventExtensions(neveropen2);
console.log(
    Object.isExtensible(neveropen2)
);


Output: 

true
false
false

Example 2: In this example, we will check if new properties can be added to an object or not using the Object.isExtensible() Method in JavaScript. The output is a Boolean value.

javascript




let neveropen1 = {};
console.log(Object.isExtensible(neveropen1));
console.log(Object.preventExtensions(neveropen1));
console.log(Object.isExtensible(neveropen1));
  
let neveropen2 = Object.seal({});
console.log(Object.isExtensible(neveropen2));
  
let neveropen3 = Object.freeze({});
console.log(Object.isExtensible(neveropen3));


Output: 

true
[object Object]
false
false
false

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

Supported Browsers: The browsers supported by Object.isExtensible() method are listed below: 

  • Google Chrome 6 and above
  • Edge 12 and above
  • Firefox 4 and above
  • Internet Explorer 9
  • 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