I understand what the double not operator does in javascript. I'm curious about it's use though and whether or not a recent assertion that I made is correct.
I said that if (!!someVar)
is never meaningful nor is (!!someVar && ...
because both the if
and the &&
will cause someVar to be evaluated as a boolean so the !! is superfluous.
In fact, the only time that I could think of that it would be legitimate to use the double not operator is if you wanted to do a strict comparison to another boolean value (so maybe in return value that expects true or false explicitly).
Is this correct? I started to doubt myself when I noticed jQuery 1.3.2 used both if (!!someVar)
and return !!someVar && ...
Does the double not have any actual effect in these situations?
My personal opinion is that it just leads to confusion. If I see an if statement, I know it's evaluating it as a boolean.