Object Frozen() method

Find out all the information about the JavaScript Frozen() method of the Object object

The JavaScript Frozen() method of the Object object takes an object as a parameter and returns the same object. The object passed as a parameter is mutable, and now it is an immutable object. No attributes can be added, no attributes can be deleted, and no attributes can be changed.


const dog = {}
dog.breed = 'Siberian Husky'
const myDog = Object.freeze(dog)

Object.isFrozen(dog) //true Object.isFrozen(myDog) //true dog === myDog //true dog.name = ‘Roger’ //TypeError: Cannot add property name, object is not extensible

See alsoObject.isFrozen()

In the example, bothdogwithmyDogWas frozen. The parameter is passed as a parameter toObject.freeze()It is a sudden change and cannot be thawed. It is also returned as a parameter, sodog===myDog(This is the exact same object).

callObject.freeze()Equivalent toObject.preventExtensions()In order to prevent the object from defining more properties, and to set all properties to be non-configurable and non-writable.

Download mine for freeJavaScript beginner's manual

More js tutorials: