CodesJava

Easy learning with example program codes

Reflect.isExtensible() JavaScript

The JavaScript Reflect.isExtensible() method determines if an object is extensible or not. It is similar to Object.isExtensible().

Syntax:

Parameters:
target: It represents the object which to check if it is extensible.

Return:
It returns true if the object is extensible otherwise returns false.

Note: It throws TypeError, if target is not an Object.

Reflect.isExtensible() VS Object.isExtensible()

Reflect.isExtensible(31);
// It throws TypeError: 31 is not an object

Object.isExtensible(31);
// It returns false

Example 1:

<!DOCTYPE html>
<html>
<body>
<script>
const obj = {prop:100};  
document.write(Reflect.isExtensible(obj));   
</script>
</body>
</html>

Output:

true

Example 2:

<!DOCTYPE html>
<html>
<body>
<script>
 
const object1 = {};
 
document.write(Reflect.isExtensible(object1));
document.write("</br>");
 
Reflect.preventExtensions(object1);
 
document.write(Reflect.isExtensible(object1));
document.write("</br>");
 
const object2 = Object.seal({});
 
document.write(Reflect.isExtensible(object2));
 
</script>
</body>
</html>

Output:

true
false
false
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status