JavaScript Object freeze() method
prevents any changes to an object

Object.freeze() method prevents any changes to an object.

syntax

Object.freeze(obj)

obj The object to freeze.

A frozen object can no longer be changed: new properties cannot be added, existing properties cannot be removed.

Frozen objects are read-only.

No modification, addition or deletion of properties are allowed.

Freezing an object is the highest integrity level that JavaScript provides.

Freezing an object does not allow new properties to be added to the object and prevents removing or altering the existing properties.

Object.freeze() preserves the enumerability, configurability, writability, and prototype of the object.

Nothing can be modified, added to or removed from a frozen object. Any attempt to do so will fail ↴

Object.freeze() method will throw a TypeError in strict mode.

Object.freeze() method will fail silently in non-strict mode.

Object.isFrozen() method can be used to check if an object is frozen.

syntax description
prevent any changes to myObject
Object.freeze(myObject)