CKTIS / JavaScript
Object.is: SameValue comparison
Object.is compares two values without coercion, treating NaN as equal to itself and distinguishing +0 from -0.
Version: ECMAScript 2015 onward; example target: Node.js 24.22.2
Syntax
Object.is(value1, value2)Object.is(value1, value2) returns a boolean using the specification’s SameValue relation. It performs no type coercion: 1, 1n, and "1" are different. For most values it matches ===, but Object.is(NaN, NaN) is true, while Object.is(+0, -0) is false.
Objects, functions, and Symbols compare equal only when both arguments are the same identity value; the method does not compare structure or contents. It is useful for detecting an actual value change, handling NaN, and cases where the sign of zero matters, such as 1 / -0 producing -Infinity.
The method has existed since ECMAScript 2015. SameValue itself invokes no argument methods, Proxy traps, or conversions and throws no exceptions. An exception can still occur earlier while evaluating an argument expression. Map and Set use the different SameValueZero relation, which does not distinguish the two signed zeros.
Examples
const item = {};
const other = {};
console.log(Object.is(NaN, NaN), NaN === NaN);
console.log(Object.is(0, -0), 0 === -0);
console.log(Object.is(item, item), Object.is(item, other));
console.log(Object.is(1, 1n), Object.is("1", 1));Result
true false false true true false false false
The example contrasts Object.is with === for NaN and signed zero, then shows object identity and no coercion.