JavaScript | Object.isExtensible() Method

The Object.preventExtensions() method in JavaScript is standard built-in objects which checks whether an object is extensible or not.

Syntax:

Object.isExtensible( obj )

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

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

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

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



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

const geeks1 = {};
console.log(Object.isExtensible(geeks1));
Object.preventExtensions(geeks1);
console.log(Object.isExtensible(geeks1));
  
const geeks2 = {};  
Object.preventExtensions(geeks2);  
console.log(  
    Object.isExtensible(geeks2)  
);  

chevron_right


Output:

true
false
false

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

var geeks1 = {};
document.writeln(Object.isExtensible(geeks1)); 
document.writeln("<br>");
document.writeln(Object.preventExtensions(geeks1));
document.writeln("<br>");
document.writeln(Object.isExtensible(geeks1)); 
document.writeln("<br>");
  
var geeks2 = Object.seal({});
document.writeln(Object.isExtensible(geeks2)); 
document.writeln("<br>");
  
var geeks3 = Object.freeze({});
document.writeln(Object.isExtensible(geeks3));

chevron_right


Output:

true
[object Object]
false
false
false

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

  • Google Chrome
  • Firefox
  • IE
  • Opera
  • Safari
  • Edge

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.