Abstract equality = = in JavaScript and strict equality = = =

Source: Internet
Author: User

1. Data type: string,number,boolean,object,null,undefined

2, abstract equality: x==y

A, both data types are the same: typeof x = = typeof y

A, string:x is exactly the same as the character of the Y position, returns True, otherwise false.

b, the value of number:x and y is equal, returns True, otherwise false is returned. Exception:Nan==nan, returns false.

C, boolean:x and Y values are equal, returns True, otherwise false.

D, Object:x is the same as the Y reference, returns True, otherwise false.

E, null:x and y are Null, that is, Null==null returns True. Note: typeof null = = Object

F, undefined:x and Y are the same as Undefined, that is, undefined==undefined, returns True.

B, the two data types are different, convert to the same type and then compare:

A,undefined = = NULL, returns True

B,True==1, return true;false==0, return True

C, 1==new String ("1"), returns True, "2" ==new number (2), returns True.

3, Strictly equal: x===y

A, the type is not equal, the return is False

B, note:

NULL = = = NULL, returns TRUE.

undefined = = = Undefined, returns TRUE.

    Null = = = Undefined, return false.

Nan = = = Nan, returns false.

Conclusion: The difference between strict and abstract, such as strict first requirement type, in the comparison process does not perform type conversion, abstract and so on the type of the comparison object will perform the conversion, and then converted to the same type before it is worth comparing.

Abstract equality = = in JavaScript and strict equality = = =

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.