A brief analysis of the new value-added comparison function object.is_javascript skills of JavaScript ES6

Source: Internet
Author: User

Before object.is, we compare values using the two equal sign "= =" or the three equal sign "= =", the three equals is more rigorous, as long as the comparison of the two types of different immediately return false.

In addition, there is and only one value is not equal to itself, it is Nan

Now ES6 added a object.is, let comparison operation of the river is more chaotic.

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//t Rue
Object.is (True, True)//true
 
NULL = NULL/TRUE
object.is (null, NULL)/true
 
undefined = = = Undef ined//True
object.is (undefined, undefined)/true

But for Nan, 0, +0,-0, and "= =" is different

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 about JavaScript ES6 the new value-added comparison function object.is all content, hope to everybody's study work can help.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.