Looking through the source code of one of our projects, I\'ve found some amount of places where we\'re using three exclamation marks in conditional statements, like so:
In javascript, it's a way to show that what you are evaluating is not a boolean but a truthy or falshy.
So for truthy/falshy values you either use !!
or !!!
and for booleans !
or nothing.
This is simply for readability.
It is the same as one exclamation mark. The key idea behind it is to improve visibility for the programmer. Compiler will optimize it as single '!' anyway.
There is no difference between !a
and !!!a
, since !!!a
is just !!(!a)
and because !a
is a boolean, !!(!a)
is just its double negation, therefore the same.
Consider:
var x;
console.log(x == false);
console.log(!x, !x == true);
console.log(!!x, !!x == true, !!x == false);
... the console output is:
false
true true
false false true
notice how, even though x is "falsey" in the first use, it is not the same as false.
But the second use (!x) has an actual boolean - but it's the opposite value.
So the third use (!!x) turns the "falsey" value into a true boolean.
...with that in mind, the third exclamation point makes a TRUE negation of the original value (a negation of the "true boolean" value).
ETA:
OMG! I can't believe I didn't notice that this is a TRIPLE exclamation point question! Even after it was specifically pointed out to me.
So, while my answer is hopefully useful to someone, I have to agree with the others who have posted that a triple-exclamation is functionally the same as a single.
The first double exclamation marks turned to a boolean value any falsy value of the object (undefined, null, 0) or any truthy value, then the third one negates it.