Skip to content
Advertisements

Object.isExtensible()

Why Object.isExtensible ?

Object.isExtensible () indicates whether to add new properties to an object and returns this result.

Note that this is not a method to be invoked on an object: it is a global function and you must pass an object to it.

Syntax:

Object.isExtensible( object )

  • object (required): The object to test.
  • return: true if the object can be extended with new properties, or false if it cannot.

JavaScript Object.isExtensible Examples

Example 1

        console.log(Object.isExtensible({}));
        console.log(Object.isExtensible(3));
        console.log(Object.isExtensible("myObject"));

output:

true
false
false


Example 2

        let myObj = {
            name: "rick",
            age: 32
        };

        console.log(Object.isExtensible(myObj));

        myObj.surname = "allen";
        console.log(myObj.surname)

output:

allen


Example 3


        var empty = {};
        let arr1 = Object.isExtensible(empty);
        console.log( arr1 )

        var frozen = Object.freeze({});
        let arr2 = Object.isExtensible(frozen);
        console.log(arr2)

        var sealed = Object.seal({});
        let arr3 = Object.isExtensible(sealed);
        console.log(arr3)

        Object.preventExtensions(empty);
        let arr4 = Object.isExtensible(empty);
        console.log(arr4)

output:

true
false
false
false


Sources


Browser Support

Chrome6
Edgeyes
Firefox4
Internet Explorer9
Opera12
Safari5.1
Android webviewyes
Chrome for Androidyes
Edge mobileyes
Firefox for Android4
Opera Androidyes
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: