• JavaScript Video Tutorials

JavaScript - Reflect.isExtensible() Method



The Reflect.isExtensible() method is a built-in JavaScript method that is used to determine whether an object is extensible or not. An extensible object is the one that may have new properties added to it using the bracket notation or dot notations. In contrast, a non-extensible object is one that cannot have new properties added to it.

Similar to Object.isExtensible() method, Reflect.isExtensible() method does not throw an error if the target is not an object. Instead, it returns false.

Syntax

Following is the syntax of JavaScript Reflect.isExtensible() method −

Reflect.isExtensible( obj )

Parameters

This method accepts only one parameter. The same is described below −

  • obj − The target object to check if it is extensible.

Return value

This method returns the Boolean value indicating if the target is extensible or not.

Examples

Example 1

Let's look at the following example, where we are going to check the objects extensibility.

<html>
   <style>
      body {
         font-family: verdana;
         color: #DE3163;
      }
   </style>
   <body>
      <script>
         let x = {};
         document.write(Reflect.isExtensible(x));
      </script>
   </body>
</html>

If we execute the above program, it will displays a text on the webpage.

Example 2

Consider another scenario where we are going to make an object non-extensible.

<html>
   <style>
      body {
         font-family: verdana;
         color: #DE3163;
      }
   </style>
   <body>
      <script>
         let x = {};
         Reflect.preventExtensions(x);
         document.write(Reflect.isExtensible(x));
      </script>
   </body>
</html>

On executing the above script, it will displays a text on the webpage.

Example 3

In the following example, we are going to check the extensibility of a sealed object.

<html>
   <style>
      body {
         font-family: verdana;
         color: #DE3163;
      }
   </style>
   <body>
      <script>
         let x = {};
         Object.seal(x);
         document.write(Reflect.isExtensible(x));
      </script>
   </body>
</html>

When we execute the above script, the output window will pop up, displaying the text on the webpage.

Example 4

Following is the example, where we are going to check the extensibility of a frozen object.

<html>
   <style>
      body {
         font-family: verdana;
         color: #DE3163;
      }
   </style>
   <body>
      <script>
         let x = {};
         Object.freeze(x);
         document.write(Reflect.isExtensible(x));
      </script>
   </body>
</html>

On running the above code, the output window will pop up, displaying text on the webpage.

Advertisements