Double not (!!) vs type coercion in JavaScript

Is there any advantage other than specifying an explicit conversion, using a double operator in JavaScript? It seems that these days people like to check for new APIs using double no, but I never read any benefits.

if(!!window.File)
    // The File API is supported.
else
    // Your browser sucks.

One thing I read is that it is a short, obscure way to enter letters in boolean, however, when it is used in this context, the object will automatically loop into boolean, since we are checking, defined.

In short, why do people perform two Boolean operations on an engine?

+5
source share
2 answers

, . .

, , - , bool, , ...

function isNotFalsy(val) { return !!val; }

, . , , .

+7

!! if.
, if .

var x = ""; // a falsy value
!x // true
!!x // false

if (x) === if (!!x)
+1

All Articles