JS equality operator detailed _javascript skills

Source: Internet
Author: User
Tags numeric numeric value

1. Equal = = and unequal!=

Convert operands first and then compare equality

Equality and inequality follow the following rules when converting different data types:

1.1 If one operand is a Boolean, convert it to a numeric value---False to a 0,true conversion to 1 before comparing equality;

1.2 If one operand is a string and the other operand is a numeric value, convert the string to a numeric value before comparing equality

1.3 If an operand is an object, another is not, then the valueof () method of the object is invoked, and the resulting base type value is compared with the preceding rule

1.4 null and undefined are equal.

1.5 You cannot convert null and undefined to any other value until you compare equality

1.6 If an operator is Nan, the equality operator returns FALSE, and the inequality operator returns true, even if the two operands are Nan.

1.7 If two operands are objects, compare whether they point to the same object

An expression Value
Null = = undefined True
"Nan" = = Nan False
5 = = NaN False
Nan = = Nan False
Nan!= nan True
5 = "5" True
false = = 0 True
true = = 1 True
true = = 2 Flase
Undefined = 0 False
NULL = 0 False

2. Congruent = = and full inequality!==

Two operands equal returns True when not converted, and not equal returns false;

undefined = = Null;//true

Undefined = = null;//false

The above JS equality operator is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.

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.