Home >Web Front-end >JS Tutorial >ECMAScript6 new value comparison function Object.is_javascript skills
Before this, we used the double equal sign "==" or the triple equal sign "===" to compare values. The third equal sign is more strict. As long as the types of the two parties are different, false will be returned immediately.
In addition, there is and is only one value that is not equal to itself, it is NaN
Now ES6 adds another Object.is, making the world of comparison operations even more confusing. In most cases, Object.is is equivalent to "===", as follows
1 === 1 // true Object.is(1, 1) // true 'a' === 'a' // true Object.is('a', 'a') // true true === true // true Object.is(true, true) // true null === null // true Object.is(null, null) // true undefined === undefined // true Object.is(undefined, undefined) // true
But for NaN, 0, 0, -0, it is different from “===”
NaN === NaN // false Object.is(NaN, NaN) // true 0 === -0 // true Object.is(0, -0) // false -0 === +0 // true Object.is(-0, +0) // false
The above is the entire content of this article, I hope you all like it.