Toolbox-XToolbox-X
GuardsChecker Functions

Check Deep Equality

Performs deep comparison between two values (arrays, objects, and primitives) to determine if they are structurally and value-wise equal.

isDeepEqual

Performs a deep comparison between two values (arrays, objects, and primitives) to determine if they are structurally and value-wise equal.

Info

This function is one of the foundational utilities, used internally throughout the package to compare arrays, objects, or any deeply nested structures.


Import

import { isDeepEqual } from 'toolbox-x';
// or
import { isDeepEqual } from 'toolbox-x/guards';

Signature

isDeepEqual(a: unknown, b: unknown): boolean

Usage Examples

playground.ts

API Reference

Parameters

NameTypeDescription
aunknownFirst value to compare.
bunknownSecond value to compare.

Returns

  • true if the values are deeply equal.
  • false otherwise.

How it Works

  • Strict Equality First: If a and b are the same reference or primitive value, returns true immediately.
  • Type & Null Checks: If types differ or either value is null, returns false unless both are strictly equal.
  • Array Handling: Arrays compared recursively, including nested arrays.
  • Object Handling: Objects compared recursively, ensuring both keys and values match exactly.
  • Shallow/Deep: Works for deeply nested arrays/objects as well as simple values.

Key Features

  • Recursive & Robust: Handles arbitrary nesting for arrays and objects.
  • Type Safety: Works generically for any consistent types.
  • Foundational Utility: This deep comparison utility powers internal checks across many toolbox functions (e.g., deduplication, merging, diffing, and more).

Limitations

  • No Cycles Supported: Will stack overflow on circular references.
  • No Symbol/Function/Date Support: Only works for plain objects, arrays, and primitives. Special types (functions, Dates, Maps, Sets, Symbols) are not deeply compared.
  • No Non-Enumerable or Prototype Chain: Only own keys are compared, prototype chain & non-enumerable properties are ignored.
  • No Partial/Object Subset Comparison: Strict equality over all keys and values only.

Notes

  • If you compare objects with arrays, types, or keys in different order but same values, equality will follow JavaScript’s structure (order matters in arrays, not in objects).
  • For performance sensitive code, avoid using on excessively large or deeply nested structures unless necessary.
  • This function is extensively used internally in toolbox-x for object/array equality checks.

  • Deduplicating structurally equal objects/arrays.
  • Testing and assertion helpers.
  • Data merging, diffing, or synchronization.
  • Safely comparing complex API payloads or configurations.

Last updated: Sun, Jun 14, 2026 08:37:01PM (UTC)

On this page