JavaScript Object.freeze() Method
The Object.freeze() static method makes an object unchangeable: properties can't be added, removed or modified.
Description
The Object.freeze() static method freezes an object: no new properties can be added, existing ones can't be removed, and their values can't be changed. In strict mode (including modules and classes), attempting a change throws a TypeError; otherwise it silently fails.
Freezing is shallow: objects nested inside a frozen object can still be changed unless you freeze them too. Note that const is different: it stops a variable being reassigned, not the object it holds from being changed.
Freezing an object in development can catch accidental mutations early, since attempts to change it throw in strict code. Arrays can be frozen too, which stops push() and other mutating methods from working. To freeze an object and everything inside it, write a small recursive "deep freeze" function that freezes each nested object.
Syntax
Object.freeze(obj)Parameters
- objThe object to freeze.
Return Value
The same object, now frozen.
Example
Browser Support
The following information will show you the current browser support for the Object.freeze() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





