Possible Duplicate:
What is the !! (not not) operator in JavaScript?
What does the !! operator (double exclamation point) mean in JavaScript?
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
.
-
Is there any benefit to using that compared to
boolean(foo.bar)
? -
foo.bar can be evaluated in an if as is because
0 === false
already, so why go through the conversion? (someVar is not reused anywhere else)