CKTIS / JavaScript
Object.isExtensible: whether an object accepts new properties
Object.isExtensible returns a boolean indicating whether new own properties can still be added to an object.
Version: ECMAScript 5 onward; primitives return false since ECMAScript 2015; example target: Node.js 24.22.2
Syntax
Object.isExtensible(obj)Object.isExtensible(obj) invokes an object’s internal [[IsExtensible]] method and returns its boolean. A new ordinary object is extensible. Object.preventExtensions, Object.seal, and Object.freeze change this state to false; for an ordinary object, extensibility cannot later be restored.
Non-extensibility blocks new own properties, but by itself does not freeze existing ones. An existing writable property can still change value, and a configurable property can be deleted or reconfigured within its descriptor rules. Therefore a false result is not equivalent to either Object.isSealed or Object.isFrozen.
The method has existed since ECMAScript 5; since ECMAScript 2015 every primitive simply returns false instead of throwing. A Proxy can run its isExtensible trap, whose result is converted to boolean. That result must match the target’s actual extensibility or TypeError is thrown; an exception from the trap also propagates.
Examples
const open = { value: 1 };
const closed = Object.preventExtensions({ value: 1 });
console.log(Object.isExtensible(open), Object.isExtensible(closed));
closed.value = 2;
console.log(closed.value, Reflect.defineProperty(closed, "extra", { value: 3 }));
console.log(Object.isExtensible(7));
const proxy = new Proxy(closed, { isExtensible() { return true; } });
try { Object.isExtensible(proxy); } catch (error) { console.log(error.name); }Result
true false 2 false false TypeError
The example compares open and closed objects, changes an existing value, rejects a new property, and exercises a Proxy invariant.