protection

Object.isFrozen

Returns true if the object is frozen — non-extensible, and every own property is non-configurable and (if a data property) non-writable. Primitives are considered frozen.

Object.isFrozen(obj)

Parameters

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

Examples

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

Logs false — plain objects are extensible

console.log(Object.isFrozen(Object.freeze({ a: 1 })));

Logs true

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

Logs true — primitives are treated as frozen

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

Logs true — an empty non-extensible object is trivially frozen

Gotcha

Empty non-extensible objects report as frozen because there are no properties to violate the rule. Does NOT recurse — returns true even if nested objects are mutable.

Related methods

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