The use of the triple exclamation mark

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.


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.


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.