JavaScript .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, orObject.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:
truefalse
Codebyte Example
Following is a runnable example that demonstrates the Object.isExtensible() static method:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn JavaScript on Codecademy
- A full-stack engineer can get a project done from start to finish, back-end to front-end.
- Includes 51 Courses
- With Professional Certification
- Beginner Friendly.150 hours
- Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
- Beginner Friendly.15 hours