The difference between "js" = = = = = = =

Source: Internet
Author: User

1, for String,number and other basic types, = = and = = = There is a difference

1) Comparison of different types, = = Comparison of "converted to the same type of value" to see if "value" is equal, = = = If the type is different, the result is not equal to 2) the same type comparison, direct "value" comparison, the results of the same 2, for Array,object and other advanced types, = = and = = = There is no difference betweenMake a "pointer address" comparison 3, the basic type and the advanced type, = = and = = = There is a difference1) for = =, the advanced conversion to the underlying type, the "value" Comparison 2) because the type is different, = = = The result is False
 
Arithmetic rules for strict operators

Equality operators

The equality operator, when comparing data of the same type,

Exactly the same as the strict equality operator.

When comparing different types of data,

The equality operator first converts the data into a type and then compares it with the strict equality operator

(1) Different types of values

If the two values are of different types, return false directly.

(1) Value of the original type

Data from the original type is converted to a numeric type and then compared.

Both the string and the Boolean value are converted to numeric values.

So there will be a second string output in the problem of the main question.

(2) Primitive type values of the same class

When comparing values (numeric, String, Boolean) of the original type of the same type,

Returns True if the value is the same, false if the value is different.

(2) Comparing objects to primitive type values

objects, which are generalized objects, including numbers and functions, are compared to the values of the original type.

The object is converted to a value of the original type and then compared.

(3) Composite type values of the same class

When comparing data from two composite types (objects, arrays, functions),

Instead of comparing their values for equality, they are compared to whether they point to the same object.

(3) Undefined and null

Undefined and null when compared to other types of values,

The results are false, and they compare to true when compared to each other.

(4) undefined and null

Undefined and null are strictly equal to themselves.

null === null  //trueundefined === undefined //true

(4) Disadvantages of the equality operator

The type conversions that are hidden by the equality operator introduce some counterintuitive results.

‘‘==' 0 '//false0 ==  "//True0 ==  ' 0 ' //truefalse ==  ' false ' //falsefalse == Span class= "S1" > ' 0 ' //truefalse == undefined Span class= "C1" >//falsefalse == null //false< Span class= "KC" >null == undefined //true \t\r\n ' == 0 //true         

This is why it is recommended that you try not to use equality operations


Smile. Angle of rotation

qq:493177502

The difference between "js" = = = = = = =

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.