JavaScript Object.freeze() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Object

Definition

Object.freeze(obj) locks an object. You cannot add properties, delete properties, or change existing values on that object.

The freeze is shallow: nested objects inside are not frozen unless you freeze them too. The method returns the same object.

Syntax

Call Object.freeze() like this. Start with this line.

JavaScript
Object.freeze(obj)
CallWhat it does
Object.freeze(obj)Freezes obj in place and returns the same object.

Built into JavaScript. Call on Object — no import required.

Library declarations
JavaScript
Object.freeze(obj)
JavaScript
freeze<T>(o: T): Readonly<T>;

Parameters

ParameterDescription
objRequired. The object to freeze. Primitives are returned as-is.

Return Value

Return ValueDescription
objectThe same object, now frozen.

JavaScript Examples

Example 1 — Basic Use

Freeze a config object, then try to change it in non-strict mode.

JavaScript
var config = { api: "v1", debug: true };
Object.freeze(config);

config.debug = false;
console.log(config.debug);  // true
Try It Yourself

How It Works

  1. Freeze first. Object.freeze(config) locks the object.
  2. Assignment ignored. Setting debug to false does nothing in non-strict mode.
  3. Value stays. config.debug is still true.

Example 2 — Add and Delete Blocked

Frozen objects also reject new keys and deletes.

JavaScript
var config = { api: "v1", debug: true };
Object.freeze(config);

config.mode = "prod";
delete config.api;

console.log(config.mode);  // undefined
console.log(config.api);   // v1
Try It Yourself

How It Works

  1. No new keys. Adding mode is blocked, so it stays undefined.
  2. No deletes. delete config.api fails, so api remains "v1".
  3. Object stays put. A frozen object keeps its shape and values.

Example 3 — Check With isFrozen

Use Object.isFrozen() to see whether an object is locked.

JavaScript
var config = { api: "v1", debug: true };
Object.freeze(config);

console.log(Object.isFrozen(config));  // true
Try It Yourself

How It Works

  1. Freeze the object. Object.freeze locks config.
  2. Ask isFrozen. Object.isFrozen(config) returns true.
  3. Useful guard. Check before you assume an object can still be edited.

Browser & Runtime Support

Object.freeze() has been part of JavaScript since ES5 and is Baseline Widely available.

✓ Baseline · ES5

Object.freeze()

Supported in all modern browsers and Node.js. Also available in Internet Explorer 9+.

99% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Object.freeze Excellent

Bottom line: Use Object.freeze() for shallow locks. Remember nested objects stay mutable unless frozen too.

Frequently Asked Questions

It locks an object so you cannot add, remove, or change its own properties. It returns the same object.
No. Only the top-level object is frozen. Nested objects can still change unless you freeze them as well.
Call Object.isFrozen(obj). It returns true after a successful freeze.
seal() stops adding or removing properties but still allows changing existing values. freeze() also blocks value changes.
In strict mode, yes. In non-strict mode, forbidden changes fail silently and the object stays the same.

Next: fromEntries()

Build an object from [key, value] pairs.

fromEntries() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful