deepEqual(): Comparing Complete Values
deepEqual() tests whether two values have the same content throughout their structure. Unlike a simple identity test, it is intended for arrays, matrices, objects, and nested collections where every corresponding member matters. For example, deepEqual([1, 2], [1, 2]) is true, while deepEqual([1, 2], [2, 1]) is false because order differs.
What “deep” means
A deep comparison descends into nested values rather than comparing only the outer container. That makes it useful for checking expected results in calculations, validating imported data, and confirming that a transformation preserved information. Use equal() for ordinary equality and compare() when an ordering result is more useful than a boolean.
Be deliberate about numeric precision. Values that print similarly can still differ by a tiny floating-point amount, so exact deep equality is not usually the right test for measured or iterative results. Compare an error against a tolerance with abs() instead. For matrices, inspect dimensions with size() before diagnosing a failed comparison.
Practical checks
deepEqual is especially helpful after clone(), parsing, or reshaping data: it can verify that values match while remaining separate values in a workflow. It does not mean two values are mathematically “close”; it means their represented structure and contents agree exactly.