JavaScript-2 the difference between an equal sign and 3 equals sign

Source: Internet
Author: User

In short, = = equality equivalent, = = = Identity identity.
= =, when the value types on both sides are different, type conversion is performed before comparison.
= = =, do not type conversion, different types of certain range.

Or:

= Assignment operator
= = equals
= = = Strictly equal To

----------------------------------------------------------------------------

The following are respectively explained:
First say = = =, this is relatively simple. The following rules are used to determine if two values are equal to = = =:
1. If the type is different, [unequal]
2, if two are numeric, and is the same value, then [equal]; Exception) is, if at least one of them is Nan, then [unequal]. (Determine if a value is Nan and can only be judged by isNaN ())
3. If two are strings, the characters are the same for each position, then [equal]; otherwise [unequal].
4, if the two values are true, or both are false, then [equal].
5. If all two values refer to the same object or function, then [equal]; otherwise [unequal].
6, if two values are null, or both are undefined, then [equal].


Say = =, according to the following rules:
1, if two value types are the same, do = = = comparison.
2. If two value types are different, they may be equal. Type conversions are then compared according to the following rules:
A, if one is null and one is undefined, then [equal].
B, if one is a string, one is a numeric value, the string is converted to a numeric value and then compared.
C, if any value is true, convert it to 1 and then compare it to 0 if either value is false.
D, if one is an object and the other is a numeric or string, convert the object to the value of the underlying type and then compare it. The object is converted to the underlying type, using its ToString or ValueOf method. JS Core built-in class, will try to valueof before ToString, the exception is that date,date is using the ToString conversion. Non-JS core of the object, so that (more trouble, I do not understand)
E, any other combination, are [unequal].

Example:
"1" = = True
Type, true will first be converted to a value of 1, now become "1" = = 1, and then the "1" into 1, compared to 1 = 1, equal.

= Assignment operator
= = equals
= = = Strictly equal To

----------------------------------------------------------------------------
Example:
var a = 3;
var B = "3";

A==b returns True
A===b return False

Because the type of A/b is different
= = = is used for rigorous comparative judgment.

JavaScript-2 the difference between an equal sign and 3 equals sign

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.