Name

Object.isFrozen() — is an object immutable?

Availability

ECMAScript 5

Synopsis

Object.isFrozen(o)

Arguments

o

The object to be checked

Returns

true if o is frozen and immutable, or false if it is not.

Description

An object is frozen if all of its non-inherited properties (except those with setter methods) are read-only, and if it is sealed. An object is sealed if no new (non-inherited) properties can be added to it, no existing (non-inherited) properties can be deleted from it. Object.isFrozen() tests whether its argument is frozen or not. Once frozen, an object can never be unfrozen.

The usual way to freeze an object is by passing it to Object.freeze(). It is also possible to freeze an object by passing it to Object.preventExtensions() and then using Object.defineProperty() to make all of its properties read-only and nondeletable.

Note that this is not a method to be invoked on an object: it is a global function and you must pass an object to it.

Get JavaScript: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.