JavaScript = = = and = = =

Source: Internet
Author: User

1.= = equality operator

1.1 If the operands have the same type, the equivalence is judged, and true (equal) is returned if the values of the two numbers are equal, otherwise false (unequal)

1.2 If the two operand types are different, then the following rules are in order:

      • Null is equal to undefined
      • One is a number, the other is a string, then the string is converted to a number, and the comparison
      • One of them is true, first converted to 1 (false translates to 0) in comparison
      • If one value is an object and the other is a number or a string, the object is converted to the original value (via the ToString () or valueof () method)
      • In other cases, it returns false directly.

2.= = = equals operator

2.1 If the operand type is different, it is not worth judging and returns false directly

2.2 If the operands are of the same type, the following rules are true:

      • Are numbers, they are equal if the values are the same (exceptions:nan is not equal to itself ), otherwise it is not equivalent
      • are strings, if the values of the strings are equal, otherwise they are not equivalent
      • Are Boolean, and their values are true/false, equivalent, otherwise not equal
      • If the two operands refer to the same object, the two are identical, otherwise they are not equivalent
      • Equivalent if two operands are null/undefined, otherwise not equal

JavaScript = = = and = = =

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.