原始转换表的原语

转换为字符串 转换为数字 转换为布尔值
undefinded "undefined" NaN false
null "null" 0 false
true "true" 1
false "false" 0
NaN "NaN" false
""(空字符串) 0 false
" " 0 true
2.4 (数字) 2.4 true
test (非数字) NaN true
0 0 true
1 1 true
-0 0 false
0 0 false
1 1 true
Infinity "Infinity" true
-Infinity "-Infinity" true
[] "" 0 true
[3] "3" 3 true
['a'] "a" NaN true
['a', 'b'] a,b NaN true
{} "[object Object]" NaN true
function(){} "function(){}" NaN true

大胆的价值突出了程序员可能会感到惊讶的转换

要显式转换值,可以使用 String()Number()Boolean()