Javascript equal operators and equivalent Operators

Source: Internet
Author: User

Both java, c ++, and php have equal operators and equivalent operators. Of course, except ripis.

Let's talk about it.

= Operator and = operator are used to check whether two values are equal. They use two different definitions with the same characteristics. Both operators accept any type of operation number. If the two operations are equal, both of them return true; otherwise, both return false, ===, Which is equivalent, it uses a strict definition of the same feature to check whether the two arithmetic operations are identical. = The operator is an equal operator. It uses a loose definition of the same feature to compare whether two arithmetic operations are equal.

This concept has a basic understanding.

Let's take a look at the situation where two values are equal.

=== Comparison of two operators

1. If the two values have different types, they are different.

2. If two values are of the same type as numbers, they are not equivalent unless one or both of them are (NaN ).

3. If the two values are strings and the characters at the same position in the strings are identical, they are completely equivalent. If the length or content of the strings are different, they are not equivalent.

= Comparison of two operators

1. If the two values are of the same type, their equivalence will be detected. If the two values are identical, they are equal. If they are not exactly the same, they are not equal.

2. If the two values have different types, they may still be equal (for example)

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

2) if a value is a number and another value is a string, convert the string to a number and compare it with the converted value.

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

4) if a value is an object and another value is a number or string, convert the object to the original type value and then compare it.

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.