.isExtensible()

Published Dec 20, 2023
Contribute to Docs

The .isExtensible() is a static method that returns true if the given object can have properties added to it and false if the object cannot have properties added to it.

Syntax

Object.isExtensible(newObject);
  • newObject: It is the object to be checked whether it is extensible.

Note: Objects are extensible by default. An object can be made non-extensible by using Object.freeze(), Object.preventExtensions, or Object.seal(). A non-extensible object can still have its properties modified.

Example

The following code will check if an object is extensible or not using the .isExtensible() method:

const characters = {
ArthurDent: 'Earth',
FordPrefect: 'Betelgeuse Five',
ZaphodBeeblebrox: 'Betelgeuse Seven',
};
console.log(Object.isExtensible(characters));
Object.preventExtensions(characters);
console.log(Object.isExtensible(characters));

The output for the above will be:

true
false

Codebyte Example

Following is a runnable example that demonstrates the Object.isExtensible() static method:

Code
Output
Loading...

All contributors

Looking to contribute?

Learn JavaScript on Codecademy