javascript - IE detection: what the heck does this mean? -
i looking @ piece of code detects ie browser:
if (false || !!document.documentmode) and not understanding contraption. why necessary or false , use not twice?
if loaded below file in ie9, ff or opera, ie tell me document mode there, while later 2 otherwise:
<html> <head> <script>function ld() { if (document.documentmode){ document.getelementbyid("p1").innerhtml = 'document mode detected' } else { document.getelementbyid("p1").innerhtml = 'no document mode' } }</script> </head> <body onload="ld()"> <p id="p1"></p> </body> </html> is not sufficient , why? not clear, because if replaced condition 1 in original question, result same. missing?
why necessary or false [...]
it isn't necessary. || operator, given false 1st operand, will return 2nd operand.
// lval || rval (minus short-circuiting) function or(lval, rval) { if (lval) return lval; else return rval; } or(false, 'foo') // 'foo' [...] , use not twice?
this part already has answer here on so.
two ! operators perform "toboolean" type conversion, slighter shorter version of using boolean() without new:
!!document.documentmode // true/false boolean(document.documentmode) // true/false also, if will perform same type conversion itself.
2. if toboolean(getvalue(exprref)) true so, when testing single value truthiness, !! aren't either, suggested:
if (document.documentmode)