js distinguish two and three == === of

First, == equality equivalents, === identity identity.
== different, when value types both sides, first type conversion, and then compared.
==, not the type of conversion, a certain range of different types.

The following illustrate:
Let me talk ===, this is relatively simple. The following rules to determine whether two values are equal ===:
1, if a different type, it [unequal]
2, if the two values are, and the same value, then [equal]; (! Exception) that is if at least a NaN, then [unequal]. (Determines whether a value is NaN, only with isNaN () to determine)
3, if the two are strings, each character position are the same, then [equal]; otherwise [unequal].
4, if the two values are true, or are false, then [equal].
5, if the two values refer to the same object or function, then [equal]; otherwise [unequal].
6, if the two values are null, or is undefined, then [equal].
== Moreover, according to the following rules:
1. If the two values are the same type, for === comparison.
2, if the two values are different types, they may be equal. The following type conversion rules further comparison:
   A, if one is null, a is undefined, then [equal].
   B, if a string, a numerical value is, the string into a numerical value and then compared.
   c, such that either value is true, then convert it to a comparator; if either value is false, then convert it to 0 comparison.
   d, if one object and another number or string, the value of the underlying object into another type of comparison. It is converted into an object base type, or using its toString valueOf method. js core built-in classes, will try to precede toString valueOf; exceptions are Date, Date utilization is toString conversion. Js non-core subject, so to say (too much trouble, I do not quite understand)
   E, any other combination, are [not equal to].

Example:
"1" to true ==
  types ranging, true value will be converted to 1, now becomes "1" = 1, then "1" is converted to 1, 1 == 1 Comparative equal.

= Assignment operator
== equal
=== strict equality
Example:
var A =. 3;
var = B ". 3";

A == B returns to true
A == B returns false

because a, b is not the same type
=== for strict comparison judgment

Reproduced in: https: //www.cnblogs.com/Alenliu/p/4049902.html

Guess you like

Origin blog.csdn.net/weixin_33860553/article/details/93470042