Equality operator = = and equivalent operator = = =

Source: Internet
Author: User

The equality operator = = and the equivalent operator, = = =, can be used to determine whether the data is equal, return a Boolean type of data, and the = = operator when comparing, the requirement type is not necessarily the same, the value is converted after the data type is equal. When the = = = operator is compared, the requirement type must be the same and the value must be the same.

Condition of = = = Operator:

1, if the types of operations are not the same, then not equivalent;

2, if the operand type is number, then compare two values (any one is Nan, then also not equal) is equal;

3, if the operand type is a Boolean, then the two operands are true or false is equivalent;

4. If the operand type is an object type, then two operands must be referenced to the same object, even if the properties of the referenced two objects are identical, they cannot be judged equal;

5, the operand null equals only null;

6, the operand undefined can only be equated with undefined;

Condition of the = = Operator:

1. If the operands are of the same type, then by the = = = operator;

2. If one operand is number and the other is a Boolean, then the Boolean is converted to 0 or 1, and then the number is equal;

3. If an operand is Nan, the result must not be equal;

4, NULL, Undefined, "", 0, False equal;

5, 1, true equals;

6, non-empty string, true equality;

7, if one operand is number, the other is a string type, then the string is converted to number, and then the number of the judge;

8. If one operand is an object and the other is number or string, then the object is converted to the base type and then compared. When an object is converted to a base type, the ValueOf method of the object is typically called first to return a basic type of data. If the valueof method does not return a basic type of data, then call the ToString method, return a string, and then judge the equality. But the difference is the date object, which is called the ToString method to return a string, and then determine the equality.

The rule for equality conversions is that the operands are converted as far as possible to the number type;

"1" = = true;

The execution of this expression is to convert the string "1" to a value of 1, and then convert the Boolean value true to the value 1, and then determine the equality.

Equality operator = = and equivalent operator = = =

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.