This is basically one way of saying that if the number if not null
or undefined
if(+!!variableName)
doSomething();
if variableName
is 0
, empty (""
), null
or undefined
, it will translate to false
or else to true
.
For example, if
var variableName = null;
now, this will translate to (+!!null)
-> (+!true)
-> (+false)
-> false
similarly, if
var variableName = "anything";
This will translate to (+!!"anything")
-> (+!false)
-> (+true)
-> true
+
in this case has no effect on the outcome, so can be safely removed.
In fact, whole conditional expression can be replaced by
if(variableName)
doSomething();