I understand the basic concept of double-negation- conversion to bool - this is a question about the specific use before new.
I was looking for a way to detect blob support and came across this check on this page:
try { !!new Blob(); } catch (e) { return false; }
I created an example below to demonstrate the check always failing.
window.onload=function()
{
var inputBox = document.getElementById('inputBox');
try {
!!new Foo15514();
inputBox.value='supported';
} catch (e) {
inputBox.value='not supported';
}
}
<input id='inputBox' type=text/>
Without getting into whether this is a good approach for blob detection or not, the question I have is what is the point of the !!
in this case? As far as I can tell it is superfluous, but I thought I would ask in case there is something I am missing.
!!new Foo15514()
, new Foo15514()
, var j = new Foo15514()
all have the same result.
Update Just to get the ball rolling - one thought I had is that this was done to force the javascript engine to evaluate this rather than skipping it since it has no effect, which seems like a bad approach if that was the case.