revision:
The Object.isExtensible() static method determines if an object is extensible (whether it can have new properties added to it).
Object.isExtensible(obj)
Parameters:
obj : required. The object which should be checked.
const object1 = {}; console.log(Object.isExtensible(object1)); // Expected output: true Object.preventExtensions(object1); console.log(Object.isExtensible(object1)); // Expected output: false
<div> <p id="ext-1"></p> <p id="ext-2"></p> <p id="ext-3"></p> <p id="ext-4"></p> </div> <script> // New objects are extensible. const empty = {}; Object.isExtensible(empty); // true document.getElementById("ext-1").innerHTML = "extensible ? : " + Object.isExtensible(empty); // They can be made un-extensible Object.preventExtensions(empty); Object.isExtensible(empty); // false document.getElementById("ext-2").innerHTML = "extensible ? : " + Object.isExtensible(empty); // Sealed objects are by definition non-extensible. const sealed = Object.seal({}); Object.isExtensible(sealed); // false document.getElementById("ext-3").innerHTML = "extensible ? : " + Object.isExtensible(sealed); // Frozen objects are also by definition non-extensible. const frozen = Object.freeze({}); Object.isExtensible(frozen); // false document.getElementById("ext-4").innerHTML = "extensible ? : " + Object.isExtensible(frozen); </script>
<div> <p id="ext-5"></p> <p id="ext-6"></p> <p id="ext-7"></p> </div> <script> const ninjas1 = {}; console.log(Object.isExtensible(ninjas1)); document.getElementById("ext-5").innerHTML = "is extensible ? : " + Object.isExtensible(ninjas1); Object.preventExtensions(ninjas1); console.log(Object.isExtensible(ninjas1)); document.getElementById("ext-6").innerHTML = "is extensible ? : " + Object.isExtensible(ninjas1); const ninjas2 = {}; Object.preventExtensions(ninjas2); console.log( Object.isExtensible(ninjas2) ); document.getElementById("ext-7").innerHTML = "is extensible ? : " + Object.isExtensible(ninjas2); </script>
<div> <p id="ext-8"></p> <p id="ext-9"></p> <p id="ext-10"></p> <p id="ext-11"></p> <p id="ext-12"></p> </div> <script> let ninjas3 = {}; console.log(Object.isExtensible(ninjas3)); document.getElementById("ext-8").innerHTML = "is extensible ? : " + Object.isExtensible(ninjas3); console.log(Object.preventExtensions(ninjas3)); document.getElementById("ext-9").innerHTML = "prevent extensions : " + Object.preventExtensions(ninjas3); console.log(Object.isExtensible(ninjas3)); document.getElementById("ext-10").innerHTML = "is extensible ? : " + Object.isExtensible(ninjas3) let ninjas4 = Object.seal({}); console.log(Object.isExtensible(ninjas4)); document.getElementById("ext-11").innerHTML = "is extensible ? : " + Object.isExtensible(ninjas4) let ninjas5 = Object.freeze({}); console.log(Object.isExtensible(ninjas5)); document.getElementById("ext-12").innerHTML = "is extensible ? : " + Object.isExtensible(ninjas5) </script>