Object.is and SameValueZero
Object.is uses SameValue comparison: it treats NaN as equal to itself and distinguishes +0 from -0. SameValueZero, used by Set and Map keys, treats the two zero signs as equal.
Choose the comparison rule needed for the data instead of treating all equality APIs as interchangeable.
See the mechanism
falsetrueFollow one example
The results are false, true, false and 2. Set combines the two zero signs and the repeated NaN into two distinct entries. None of these operations recursively compares object fields. Two separately created records remain distinct references under these equality rules.
Predict, change and check
Predict: Would Object.is({title: "A"}, {title: "A"}) be true?
Test your explanation: Test separate objects, then compare one object with itself. Separate value comparison rules from the question of object identity.
The tasks below ask you to explain that result and apply the idea to different inputs.
Apply and distinguish
Match membership behavior to comparison behavior
Object.is exposes SameValue behavior. Set membership, Map keys and includes use SameValueZero, which groups the signs of zero but still recognizes NaN. indexOf cannot find NaN using its comparison behavior. A deduplication feature can therefore differ from a simple indexOf-based implementation.
No comparison in this lesson is a recursive record comparison. If two API responses describe the same article ID, compare the ID field under its defined type contract; do not assume the two response objects share identity. When signed zero matters, include it explicitly in the test inputs.
Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.