真值
Argument Type | Result |
Undefined | false |
Null | false |
Boolean | The result equals the input argument (no conversion). |
Number | The result is false if the argument is +0, −0, or NaN; otherwise the result is true. |
String | The result is false if the argument is the empty String (its length is zero); otherwise the result is true. |
Object | true. |
相等
==算法
Type(x) | Type(y) | Result |
x and y are the same type | See Strict Equality (===) Algorithm | |
null | Undefined | true |
Undefined | null | true |
Number | String | x == toNumber(y) |
String | Number | toNumber(x) == y |
Boolean | (any) | toNumber(x) == y |
(any) | Boolean | x == toNumber(y) |
String or Number | Object | x == toPrimitive(y) |
Object | String or Number | toPrimitive(x) == y |
otherwise… | false |
Argument Type | Result |
Undefined | NaN |
Null | +0 |
Boolean | The result is 1 if the argument is true. The result is +0 if the argument is false. |
Number | The result equals the input argument (no conversion). |
String | In effect evaluates Number(string) “abc” -> NaN “123″ -> 123 |
Object | Apply the following steps:
1. Let primValue be ToPrimitive(input argument, hint Number). |
toPrimitive算法
Argument Type | Result |
Object | (in the case of equality operator coercion) if valueOf returns a primitive, return it. Otherwise if toString returns a primitive return it. Otherwise throw an error |
otherwise… | The result equals the input argument (no conversion). |
===算法
Type(x) | Values | Result |
Type(x) different from Type(y) | false | |
Undefined or Null | true | |
Number | x same value as y (but not NaN ) | true |
String | x and y are identical characters | true |
Boolean | x and y are both true or both false | true |
Object | x and y reference same object | true |
otherwise… | false |