【发布时间】:2020-11-07 18:07:34
【问题描述】:
当我运行这段代码时,if- 块中的代码会被执行。我的假设是 if ! something,它是 null 还是 未定义?谁能解释一下?
const num = 0;
if (!num) {
console.log('Why on earth does this get printed');
}
【问题讨论】:
-
0是一个 falsy 值。这是唯一的假数。 -
而且 !falsy 等于 true
-
然后你的代码被执行了。
-
谢谢!这个问题有什么问题???我真的没有理由对此投反对票……
标签: javascript if-statement types null undefined