Possible Duplicate:
What is the !! (not not) operator in JavaScript?
I’m looking through some code and see an IF statement that looks like the one below. Can anyone tell me why there are two !!s instead of one? I’ve never seen this before and can’t dig anything up on Google because it’s ignoring the special character.
if (!!myDiv && myDiv.className == 'visible') {
}
The double not operator is used to cast a variable to the
booleantype. The dobule nots cancel each other out, but seeing as!returnstrueorfalse, you only get one of the two output.For example,
So
Casts
myDivto a boolean and tests it against true.!!myDivwill only givetrueorfalse.