JavaScript .isFrozen()

THE-Spellchecker's avatar
Published Dec 19, 2023Updated May 15, 2024
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.

  • A full-stack engineer can get a project done from start to finish, back-end to front-end.
    • Includes 51 Courses
    • With Professional Certification
    • Beginner Friendly.
      150 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours

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 celsius',
Reykjavik: '5.3 celsius',
Tokyo: '16.66 celsius',
};
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

Contribute to Docs

Learn JavaScript on Codecademy

  • A full-stack engineer can get a project done from start to finish, back-end to front-end.
    • Includes 51 Courses
    • With Professional Certification
    • Beginner Friendly.
      150 hours
  • Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.
    • Beginner Friendly.
      15 hours