Standard built-ins
Object.is()
Tests SameValue equality without coercion. It treats NaN as equal to itself and distinguishes positive from negative zero, unlike strict equality. Objects still compare by identity.
Formal Syntax & Structure
javascript syntaxjavascript
Object.is(value1, value2)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| value1 | any | First value. |
| value2 | any | Second value. |
Return Value
Boolean
True for SameValue equality.
Working Example
Example Snippetjavascript
console.log(Object.is(NaN, NaN), Object.is(0, -0));