Use of Object.isFrozen Method in JavaScript



Object.isFrozen()

Object.isFrozen() method is used to find whether an object is frozen or not. 

An object is frozen if it followed the below criteria

  • It should not be extensible.

  • Its properties should be non-configurable.

  • It shouldn't accept any new properties.

Syntax

Object.isFrozen(obj);

Parameters - Object.isFrozen() accepts an object as a parameter and scrutinizes whether it is frozen or not and returns a boolean output.

Example

In the following example Object.isFrozen() scrutinizes whether the object 'obj' is frozen or not. Since the object is not frozen, false will be displayed as the output.

 Live Demo

<html>
<body>
<script>
   var object = {
      prop1 : 5
   }
   var res = Object.isFrozen(object);
   document.write(res);
</script>
</body>
</html>

Output

false

Example

In the following example since the object 'object' is frozen by using Object.freeze(), true will be displayed as the output.

Live Demo

<html>
<body>
   <script>
      var object = {
         prop1 : 5
      }
      Object.freeze(object);
      var res = Object.isFrozen(object);
      document.write(res);
   </script>
</body>
</html>

Output

true
Updated on: 2020-06-29T11:36:06+05:30

163 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements