.isFrozen()

Published Dec 19, 2023
Contribute to Docs

The .isFrozen() static method returns true when the given object is frozen, and false if it is not. An object is considered frozen when you cannot add new properties to it, cannot change the existing properties, and cannot delete the existing properties. For example, you can freeze an with the Object.freeze() static method.

Syntax

Object.isFrozen(newObject);
  • newObj: It is the object to be checked for its frozen state.

Example

The following example checks if an object is frozen.

const avgAnnualTemps = {
Sydney: '18.7 celcius',
Reykjavik: '5.3 celcius',
Tokyo: '16.66 celcius',
};
console.log(Object.isFrozen(avgAnnualTemps));
Object.freeze(avgAnnualTemps);
console.log(Object.isFrozen(avgAnnualTemps));

The above example will give the following output:

false
true

All contributors

Looking to contribute?

Learn JavaScript on Codecademy