Open In App

JavaScript Reflect isExtensible() Method

Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • Obj: This parameter is the target object and is used to check whether it is extensible.

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.

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.

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:

  • Google Chrome 49 and above
  • Edge 12 and above
  • Firefox 42 and above
  • Opera 36 and above
  • Safari 10 and above

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



Last Updated : 07 Aug, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads