Value | Context in which value is used | |||
| String | Number | Boolean | Object |
Undefined value | "undefined" | NaN | false | Error |
null | "null" | 0 | false | Error |
Nonempty string | As is | Numeric value of string or NaN | TRue | String object |
Empty string | As is | 0 | false | String object |
0 | "0" | As is | false | Number object |
NaN | " NaN " | As is | false | Number object |
Infinity | "Infinity" | As is | true | Number object |
Negative infinity | "-Infinity" | As is | TRue | Number object |
Any other number | String value of number | As is | true | Number object |
true | "true" | 1 | As is | Boolean object |
false | "false" | 0 | As is | Boolean object |
Object | toString( ) | valueOf( ), toString( ), or NaN | true | As is |
Javascript各类型值之间的转换
最新推荐文章于 2024-08-19 15:26:06 发布
节选自《The Definitive guide,5th Edition》, 总是记不住,还是找个地方存着。。。