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 boolean
type. The dobule nots cancel each other out, but seeing as !
returns true
or false
, you only get one of the two output.
For example,
!!0 == true
So
!!myDiv == true
Casts myDiv
to a boolean and tests it against true. !!myDiv
will only give true
or false
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With