Implement Object.is()

Easy
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Implement Object.is()

Approach

Handle the two edge cases where === gives incorrect results: NaN should equal NaN (use Number.isNaN to detect both), and -0 should not equal +0 (use 1/x to distinguish via Infinity signs). For all other values, fall through to strict equality.

Complexity Analysis

Time
O(1)
Space
O(1)

Pattern

Same-Value Equality

Why It Works

The 1/x trick exploits the fact that 1/+0 is Infinity while 1/-0 is -Infinity, distinguishing the two zeros that === considers equal. Number.isNaN correctly identifies NaN which === rejects.

Updated Feb 2026