<分区>
注意:它实际上是 What is the difference between if(!!condition) and if(condition) 的副本
虽然我明白what the !! means (double not) ,出于同样的原因,它的使用对我来说没有意义 in the MDN documentation :
if (!!window.Worker) {
...
}
对于这种情况,这不是完全一样吗?
if (window.Worker) {
...
}
转换为 bool 值对我来说毫无意义,因为 if
只会在 window.Worker
存在时执行。对于 if()
条件(我认为)来说,说它是 True
或 Object
是一样的。
那么,为什么要在这里使用 !!
呢?或者,为什么 window.Worker
在 if()
中转换为 bool 值?