Open In App

JavaScript Reflect isExtensible() Method

JavaScript Reflect.isExtensible() method in JavaScript is used to check whether an object is extensible or not(Checks whether other properties can be added to it or not). This method is similar to Object.isExtensible() but it will cause a TypeError if the target is not an object.

Syntax:



Reflect.isExtensible( obj )

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

Return value: This method returns a Boolean value which indicates if the target is extensible.



Exceptions: A TypeError is an exception given as the result when the target is not an Object.

Below examples illustrate the Reflect.isExtensible() method in JavaScript:

Example 1: In this example, we will check if the object is extensible or not using the isExtensible() method in JavaScript.




const object1 = {};
 
console.log(Reflect.isExtensible(object1));
Reflect.preventExtensions(object1);
console.log(Reflect.isExtensible(object1));
 
const object2 = Object.seal({});
console.log(Reflect.isExtensible(object2));
 
const object3 = Object.seal({});
console.log(Reflect.isExtensible(object3));

Output
true
false
false
false

Example 2: In this example, we will check if the object is extensible or not using the isExtensible() method in JavaScript.




// Sealed objects are by definition
// non-extensible.
let sealed = Object.seal({})
console.log(Reflect.isExtensible(sealed));
 
let empty = {}
console.log(Reflect.isExtensible(empty));
 
// ...but that can be changed.
Reflect.preventExtensions(empty)
console.log(Reflect.isExtensible(empty));
 
// Frozen objects are also by
// definition non-extensible.
let frozen = Object.freeze({})
console.log(Reflect.isExtensible(frozen));

Output
false
true
false
false

Supported Browsers:

The browsers are supported by JavaScript Reflect.construct() Methods are listed below:

We have a complete list of Javascript Reflects methods, to check those go through the JavaScript Reflect Reference article.


Article Tags :