The difference between "= =" and "= = =" in JS

Source: Internet
Author: User

"= =" and "= = =" Are different, one is to determine whether the value is equal, one is the judgment value and the type is exactly equal. 
The following rule is used to determine whether the two values of the = = = operator comparison are equal.
1. If the two values are of different types, they are not the same.
2, if two values are numbers, and the values are the same, then unless one or two of them are Nan (in which case they are not equivalent), they are equivalent. The value Nan is never equal to any other value, including itself (strange fellow), to detect whether a value is Nan, you can use the global function isNaN ().
3, if two values are strings, and the characters in the same position in the string are exactly the same, then they are identical. If the lengths or contents of the strings are different, they are not equivalent.
4, if two values are Boolean true, or two values are Boolean false, then they are equivalent.
5. If two values refer to the same object, array, or function, then they are identical. If they refer to different objects (arrays or functions), they are not exactly equal, even if the two objects have exactly the same properties, or two arrays have exactly the same elements.
6, if two values are null or both are undefined, they are identical.

Second, the following rule is used to determine whether the = = operator Comparison of the two values are equal to determine the condition
1. If two values have the same type, then the equivalence of them is detected. If the two values are exactly the same, they are equal. If they are not identical, they are not equal.
2. If the two values are of different types, they may still be equal. Use the following rules and type conversions to detect their equality? If one value is null and the other value is undefined, they are equal.
3. If one value is a number, the other value is a string, the string is converted to a number, and then the converted value is compared.
4. If a value is true, convert it to 1 and then compare. If a value is false, convert it to 0 and then compare.
5. If one value is an object and the other value is a number or string, convert the object to a value of the original type and then bury the comparison. You can use the ToString () method of the object or the valueof () method to convert the object to a value of the original type.
The inner class of the JavaScript core language typically attempts the valueof () method transformation before attempting the ToString () method transformation, but for the date class, the ToString () method is executed before the valueof () method is converted. Objects that are not part of the JavaScript core language can convert themselves to original values in a way that is defined by the JavaScript implementation.
? The other numeric combinations are not equal.

The difference between "= =" and "= = =" in JS

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.