js中的if判断

在js中if条件为null/undefined/0/NaN/""表达式时,统统被解释为false,此外均为true哦。。。(官方原文如下:)
Boolean 表达式一个值为 true 或者 false 的表达式。如果需要,非 Boolean 表达式也可以被转换为 Boolean 值,但是要遵循下列规则:
所有的对象都被当作 true。
当且仅当字符串为空时,该字符串被当作 false。
null 和 undefined 被当作 false。
当且仅当数字为零时,该数字被当作 false。

猜你喜欢

转载自blog.csdn.net/weixin_44892460/article/details/110493693