I read an article about Test for Internet Explorer in JavaScript which states that a quick test is :
var isMSIE = /*@cc_on!@*/0;
if (isMSIE) {
// do IE-specific things
} else {
// do non IE-specific things
}
But one of the comments showed another way : ( and I have to say , it works)
if (-[1,]) {
// do non IE-specific things
} else {
// do IE-specific things
}
And so I ask :
What is so special with -[1,]
that IE doesn't recognize it while others do ?
p.s.
found another quick falsy-truthy trick
IE='\v'=='v'
[1,].toString()
in IE prior to recent versions was 1,
which when prefixed with arithmetic -
would output falsey NaN
whereas other browsers would return [1,].toString() === 1
for a truthy -1
.
Its a horrid sniffing technique, avoid it entirely and as other have commented detect support for specific features.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With