<分区>
Possible Duplicate:
Why does ('0' ? 'a' : 'b') behave different than ('0' == true ? 'a' : 'b')
'0' == false; // true
'0' || 1; // '0'
'0' ? true : false; // true
!!'0' // true
是“==”
会投'0'
-> 0
-> false
,但其他不?
我想要更多细节。
<分区>
Possible Duplicate:
Why does ('0' ? 'a' : 'b') behave different than ('0' == true ? 'a' : 'b')
'0' == false; // true
'0' || 1; // '0'
'0' ? true : false; // true
!!'0' // true
是“==”
会投'0'
-> 0
-> false
,但其他不?
我想要更多细节。
最佳答案
为您准备的 Javascript 真值表。
'' == '0' // false
0 == '' // true
0 == '0' // true
false == 'false' // false
false == '0' // true
false == undefined // false
false == null // false
null == undefined // true
" \t\r\n" == 0 // true
试一试,我想你将能够消除你的困惑。
关于javascript - 字符串 '0' 在 javaScript 中为 true|false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8623612/