Object.is and SameValueZero
In short: Object.is(a, b) behaves exactly like ===, except it fixes
two number quirks: Object.is(NaN, NaN) is true (where === says
false), and Object.is(0, -0) is false (where === says true).
Everything else matches === exactly. A close cousin called
SameValueZero — used internally by includes, Map and Set — takes
the NaN fix from Object.is but keeps the 0/-0 behaviour of ===. For
everyday code, default to ===; reach for Object.is only when NaN or
signed zero must be handled exactly.

Fix a false "value changed" alert
=== says two NaNs are different, which breaks a naive "did this value
change?" check when the value legitimately is NaN both times (a missing
sensor reading, say):
old !== next is true — the screen would redraw for nothing, forever,
because NaN never equals itself under ===. !Object.is(old, next) is
false: Object.is treats the two NaNs as the same value, so nothing
looks changed.
The values
Old reading:
NaN. New reading:NaN.
Compare Object.is against === directly
Running the same pairs through both operators side by side shows exactly where they part ways — and nowhere else:
Same-type primitives ("Blue Hour") and mismatched objects ({} vs {})
behave exactly like ===. Only the two number rows in the drawing's table
differ.
Find NaN in an array two different ways
includes and indexOf look like they should agree, but they use
different equality rules internally — includes uses SameValueZero,
indexOf uses ===:
includes finds it: true. indexOf never can, because it compares with
===, and NaN === NaN is always false, so it reports -1 — "not
found" — even though NaN is sitting right there at index 0.
Quick practice
What is Object.is(NaN, NaN)?
What is Object.is(0, -0)?
What is Object.is("5", 5)?
What does [NaN].indexOf(NaN) return?
Which rule says NaN equals NaN AND 0 equals -0?
🎯 Your turn
For the pairs (NaN, NaN) and (0, -0), explain what ===, Object.is and
includes (SameValueZero) each say, and when you would choose Object.is
in real code.
Write your explanation and submit it — there's no code to run here, just your reasoning.
