The Object.is(value1, value2) method

The Object.is() method determines whether two values are equal or not. It is similar to the === operator but there are some special cases for the Object.is() method. Here is an example that demonstrates special cases:

console.log(Object.is(0, -0));console.log(0 === -0);console.log(Object.is(NaN, 0/0));console.log(NaN === 0/0);console.log(Object.is(NaN, NaN));console.log(NaN ===NaN);

The output is as follows:

falsetruetruefalsetruefalse

Here's a handy table you might want to look at for the differences between 0==, ===, and Object.is:

While it might seem intuitive that Object.is can compare if two given ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.