Here is a javascript comparison:
(这是一个JavaScript比较:)
2 == true //false
it's said, the reason why return false, is because the comparison convert the true
to Number
datatype, and result is 1:
(据说返回false的原因是因为比较将true
转换为Number
数据类型,结果为1:)
console.info(Number(true)) // 1
My confuse is, why the comparison don't convert the number 2
to Boolean
datatype
(我的困惑是,为什么比较不将数字2
转换为Boolean
数据类型)
console.info(Boolean(2)) // true
and the 2 == true
result could be true
?
(和2 == true
结果可能是true
吗?)
ask by hh54188 translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…