Home > Web Front-end > JS Tutorial > body text

ECMAScript6 new value comparison function Object.is_javascript skills

WBOY
Release: 2016-05-16 15:55:34
Original
1291 people have browsed it

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

Copy after login

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
Copy after login

The above is the entire content of this article, I hope you all like it.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!