Is there any advantage, except indicating an explicit conversion, to using a double not operator in JavaScript? It often seems that these days, people like to check for existence of new APIs using the double not, but I have never, ever read any advantage to it.
if(!!window.File)
// The File API is supported.
else
// Your browser sucks.
The one thing that I have read is that it is a concise, obscure way to type cast to Boolean, however, when used in this context the object will be auto coerced to Boolean anyway since we are checking to see if it is defined.
In short, why do people do two Boolean operations on top of the engine's?
true
orfalse
value (like some jQuery APIs), and not just a value to be cast later. Sometimes APIs with optional parameters usetypeof
to figure out what a particular set of parameters is supposed to mean, so if it's necessary to pass in a real boolean,!!
is a quick (and perfectly safe) way to do it. It's idiomatic, and any experienced JavaScript developer should be familiar with the idiom. – Drugge