Home  >  Article  >  Web Front-end  >  ECMAScript6 new value comparison function Object.is_javascript skills

ECMAScript6 new value comparison function Object.is_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:55:341304browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn