JS equal Judgment (==,===,object.is)

Source: Internet
Author: User

JavaScript provides three different values for comparison operations:

    • Strictly equal ("triple equals" or "identity"), use = = =,
    • Loosely equal ("double equals"), using = =
    • and Object.is (ECMAScript 2015/es6 new features)

In short, when comparing two things, the double equals sign performs the type conversion;  The three equals sign will make the same comparison without a type conversion (if the type is different, only false is always returned); The object.is behaves the same as the three equals, but for NaN and 0 and +0, the last two are different, and object.is (Nan,nan) will be true . (You typically use a double or three equals sign to compare Nan with Nan, and the result is false, because IEEE 754 says.) Please note that all of these differences are related to their handling of the primitives; None of the three primitives of the operators will compare two variables with similar structural concepts. For any two different non-primitive objects, even if they have the same structure, the above three operators will be evaluated to false.

When to use object.is or third-level

Object.is will judge the object property description, if you do not need to judge the description of the attribute should take precedence of the use of three-

object Property Description ReferenceObject.defineProperty

JS equal Judgment (==,===,object.is)

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.