Favorites

JavaScript Object.freeze() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Object.freeze()
JavaScript Object Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

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

'use strict';
const config = Object.freeze({ api: '/v1', nested: { retries: 3 } });

try { config.api = '/v2'; } catch (e) { console.log(e.name); }
config.nested.retries = 5;          // nested objects aren't frozen
console.log(config.api, config.nested.retries);
console.log(Object.isFrozen(config));

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee