isEqual() function
Performs a deep equality comparison between a and b.
Unlike isMatch, which performs a partial comparison where source only needs to match a subset of properties, isEqual requires complete equality in both directions: objects must have the same set of keys, arrays the same length and order, and Map/Set the same size.
Supported types: primitives (NaN is treated as equal to NaN), Object (nested, key order irrelevant), Array (order sensitive), Date (compared by getTime), RegExp (compared by source and flags), Map (keys and values are deeply compared), Set (order irrelevant). Values of different types are never equal, and functions are compared by reference only.
Signature:
typescript
declare function isEqual(a: unknown, b: unknown): boolean;Example
ts
// Primitives (NaN equals NaN)
isEqual(1, 1); // true
isEqual(NaN, NaN); // true
isEqual("a", "b"); // false
// Full equality, unlike isMatch's partial matching
isEqual({ a: 1, b: 2 }, { a: 1 }); // false - key counts differ
isMatch({ a: 1, b: 2 }, { a: 1 }); // true - subset is enough
// Nested objects (key order irrelevant)
isEqual({ a: 1, b: { c: 2 } }, { b: { c: 2 }, a: 1 }); // true
isEqual({ a: 1 }, { a: 1, b: undefined }); // false - key counts differ
// Arrays (order sensitive)
isEqual([1, 2, 3], [1, 2, 3]); // true
isEqual([1, 2, 3], [3, 2, 1]); // false
// Date and RegExp
isEqual(new Date(1000), new Date(1000)); // true
isEqual(/abc/gi, /abc/gi); // true
// Map (keys and values are deeply compared)
isEqual(new Map([[{ a: 1 }, 1]]), new Map([[{ a: 1 }, 1]])); // true
// Set (order irrelevant)
isEqual(new Set([1, 2, 3]), new Set([3, 2, 1])); // true
// Different types are never equal
isEqual(new Date(0), {}); // false
isEqual(null, {}); // false