Possible Duplicate:(可能重复:)
So I was debuging some code and ran across this:(所以我正在调试一些代码并遇到这个:)
var foo.bar = 0; // this is actually passed from another function, adding it for context
function(foo) {
var someVar = !!foo.bar;
if (foo.bar) {
// ..stuff happens
} else {
// .. something else happens
}
}
Okay my questions is what is the point of !!
(好的,我的问题是什么意思!!
) ?(?) All that is doing is making the 0 === false
.(所有这一切都是使0 === false
。)
Is there any benefit to using that compared to boolean(foo.bar)
?(与boolean(foo.bar)
相比,使用它有什么好处?)
foo.bar can be evaluated in an if as is because 0 === false
already, so why go through the conversion?(foo.bar可以在if as as中进行评估,因为0 === false
,所以为什么要进行转换?) (someVar is not reused anywhere else)((someVar不会在其他任何地方重复使用))
ask by jpalladino84 translate from so