Equality
equality in JavaScript ES5 using '==' and '==='; and introduction to the Object.is() method in ES6, which is very similar to '==='
In this lesson, we will cover object and function improvements in ES6. As with most updates in ES6, we will be able to solve the same problems as before, with less code, and more clarity.
We will start with a nitpicky subject: comparisons. Most developers prefer ===
to ==
, as the first one considers the type of its operands.
In ES6, Object.is(a, b)
provides same value equality, which is almost the same as ===
except the following differences:
Object.is( +0, -0 )
isfalse
, while-0 === +0
istrue
Object.is( NaN, NaN )
istrue
, whileNaN === NaN
is false
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.