Explain the difference between shallow equality and deep equality in JavaScript.
Instruction: Describe shallow and deep equality and how they can be checked in JavaScript.
Context: This question tests the candidate's understanding of equality checks and how they differ when comparing objects and primitives.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
Object identity, shallow equality and deep equality are different questions. For objects, a === b asks whether both references identify the same object; it does not compare their properties. Object.is also uses object identity, while treating NaN as equal to itself and distinguishing positive and negative zero.
A shallow comparison checks selected own properties and compares their values without recursively inspecting nested objects...