For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/object/deepFreeze.md.

deepFreeze es-toolkit

Recursively freezes an object, making it and all nested objects and arrays immutable.

const frozen = deepFreeze(obj);

Usage

deepFreeze(obj)

Use deepFreeze when you want to make an object completely immutable. Object.freeze only freezes the top-level properties of an object, so nested objects can still be modified. deepFreeze recursively freezes all nested objects and arrays, so nothing can be changed at any depth.

The object is frozen in place and the same reference is returned. Objects that are already frozen are skipped, so circular references are handled safely.

import { deepFreeze } from 'es-toolkit/object';

// Nested objects are frozen too
const user = deepFreeze({ name: 'Alex', settings: { theme: 'dark' } });
user.settings.theme = 'light'; // TypeError in strict mode
// user.settings is still { theme: 'dark' }

// Arrays and the objects inside them are also frozen
const config = deepFreeze({ tags: ['admin', 'user'] });
config.tags.push('guest'); // TypeError in strict mode

Parameters

objTrequired

The object to freeze deeply.

Returns

The same object, with itself and all nested objects and arrays frozen.

T
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.