Write deepEqual(a, b). Primitives are equal if Object.is(a, b) (so NaN equals NaN). Arrays are equal if they have the same length and equal items. Plain objects are equal if they have the same keys with equal values, in any order.
An array is never equal to an object, even [] and {}.
Your code
Runs in a Web Worker in your browser. Tests use real timers, so a run takes a second or two.
Solution
function deepEqual(a, b) {
if (Object.is(a, b)) return true;
if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) return false;
if (Array.isArray(a) !== Array.isArray(b)) return false;
if (Array.isArray(a) && a.length !== b.length) return false;
const keysA = Object.keys(a);
const keysB = Object.keys(b);
if (keysA.length !== keysB.length) return false;
return keysA.every((key) => Object.prototype.hasOwnProperty.call(b, key) && deepEqual(a[key], b[key]));
}
Handle the easy cases first: identical values (with Object.is so NaN works), then anything that isn't a non-null object. Reject an array compared with an object, compare array lengths (sparse arrays like Array(2) have fewer keys than their length), compare key counts, then recurse on each key.
Checking hasOwnProperty matters: { a: undefined } and { b: undefined } have the same key count and undefined values. Follow-ups: dates, Map/Set, and cycles (track pairs you're already comparing).
In a Web Worker in your browser, with real timers and promises. Nothing is sent to a server. If your code loops forever, the run is stopped after 10 seconds.
Yes. Anything your browser supports works: classes, async/await, Map and Set, spread and optional chaining.