JavaScript equality operators and equivalent operators detail _javascript tips

Source: Internet
Author: User

the = = operator and the = = operator are used to detect whether two values are equal, and they employ two different definitions of the same trait. Both operators accept operands of any type, and if two operands are equal, they all return true, otherwise the false,=== operator is returned as the equivalent operator, and it uses the strict same trait definition to detect whether the two counts are identical, and the parents ' attention is exactly the same. The = = operator is the equality operator, which uses a relatively loose definition of the same trait to compare the equality of two operands.

There is a basic understanding of this concept.

The following is a specific decision two values are the same situation bar.

= = = Operator Two value comparison

1, if two value types are different, they are not the same

2, if the two-value type is a number and the value is the same, then unless one or two of the middle is a (NaN), they are not equal, otherwise they are equivalent

3, if two values are strings, and the characters are identical in the same position in the string, they are identical, and if the length or content of the string is different, then they are not equal.

= = Operator Two value comparison

1, if the two values are of the same type, then check their equivalence. If two values are exactly the same, they are equal. If they're not exactly the same, they're not equal.

2, if two values are of different types, they may still be equal (for a few examples)

1 if one value is null and the other is undefined, they are equal

2 If a value is a number, another value is a string, converts the string to a number, and then compares it with the converted value

3 If a value is true, it is converted to 1 and then compared. If a value is false, convert it to 0, and then compare it

4 If a value is an object, another value is a number or a string, the object is converted to the original type of value, and then compared.

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.