protection

Object.isExtensible

Returns true if new properties can be added to the object. Sealed, frozen, and preventExtensions'd objects all return false; primitives always return false.

Object.isExtensible(obj)

Parameters

Parameter Purpose
obj The value to test
returns Boolean — true if extensible

Examples

console.log(Object.isExtensible({}));

Logs true — normal objects are extensible

const o = {};
Object.preventExtensions(o);
console.log(Object.isExtensible(o));

Logs false

console.log(Object.isExtensible(Object.freeze({})));

Logs false — freeze implies non-extensible

console.log(Object.isExtensible(42));

Logs false — ES2015+ returns false for primitives (previously threw)

Gotcha

Since ES2015 this returns false for primitive values rather than throwing. Being extensible says nothing about whether existing properties are writable — check isFrozen/isSealed for that.

Related methods

← All JS Object methods · Array methods · Spread vs rest