= = and = = = in JavaScript

Source: Internet
Author: User

First, the main difference:

1. In layman's terms, = = is a comparison of values, and = = = Not only compares values, but also compares references to the same object.

2. When compared with = =, if the operands of the two numbers are of different types, they are converted first. The operand of = = = does not make any conversions.

3.if () is used in the = = judgment, case is used to determine the = = =.

For example if (null==undefined) returns True

switch (NULL) {

Case "undefined":

There's no execution here.



Second, = = = More detailed

1. If 2 value types are different, they are not equal.

2. If two values are null, or undefined, or if one is null and the other is undefined, then they are not equal.

3. If there is one, or two are Nan, they are not equal. (Nan and any object of any value are unequal, including himself.) If if (x!==x) returns True, it indicates that X is Nan).

4. If two values are numeric and the values are equal, then both are equal. 0 and-0 are equally equal.

5. If it is a string, the content, the length, the encoding is different, then they do not wait.

6. If both reference values point to the same reference object, they are equal. If you point to a different reference value, even if they have exactly the same familiarity, the same is not equal.

Third, = = more detailed

1. If two values are null, or undefined, they are equal.

2. If one is a number and the other is a string, first convert the string to a number and then compare it.

3. If one of them is a Boolean value, first turn true to 1 or false to 0, and then compare.

4. If one is an object, one is a number or a string, the object is first converted to its original value and then compared.

= = In addition to the above 4, the other different types before the comparison are unequal. It is not the same object, even if it is a two object type, but not a reference.

Iv. Specific Cases

"A" ===string ("a")//true

"A" ===new String ("a")//false




var a=/124/,b=/124/;a==b//false

var a = function.length,b= new Function (). Lenth;a==b;//false

var a = date (0), B=new date (0), c=new date ();//Any comparison of the three is false

= = and = = = in JavaScript

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.