Explanation of the world's shortest IE decision if (!+[1,])

Source: Internet
Author: User

<script type= "Text/javascript" >alert ([+]);//equivalent to alert ([1,2].tostring ());  --This is the same on IE and non-ie, will pop up " "Alert" ([1,]);//equivalent to alert ([1,].tostring ()),--in non-IE standard browser, JS engine will automatically delete the last ",", so on IE will pop up "1," and on non-ie will pop up "1" alert (+[1, ]);//According to the above explanation, this sentence on IE equivalent to alert (+ "1,"), and on non-ie equivalent to alert (+ "1"), the role of positive sign is to try to convert the string to a number, "1," of course, is not a number, and "1" can be converted to the number 1 So the final result: IE will fail to pop "NaN", instead of the number "1" on IE will pop up the  //above the + number conversion string for the number of the test var s = + "5"; alert (s+1);  / /ok, so far, we know  +[1,]  finally in IE for the NaN, in the non-IE browser is the digital 1 //below to see the very personality of Nanalert (nan==true);//Popup   Falsealert (Nan==false);//pop-up  falsealert (Nan==nan);//pop-up  false //that is NaN no matter who compares with Falsealert (! NaN);//equivalent to alert (! ( Nan==true)), according to the above explanation of course is pop true  //so, alert (!+[1,])   Finally on IE will pop up "true", and then look at Firefox and other non-IE browser performance alert ( New boolean (0));//falsealert (New boolean (1));//truealert (New boolean ( -1));//true// That is: The number 0 will be converted to false, any other number will be converted to true, so ultimately on non-IE browser is ultimately equivalent to: alert (!1),//That is, alert (!true)//will eventually get false // In summary: The following judgment will be able to determine whether the browser is ieif  (!+[1,]) {     alert ("I am a real IE browser!")} Else{    alert ("I'm Not ie!")} </script>

Note: Over time, IE9 and above have fixed the bug (unless it is set to compatibility mode), which has already been pointed out in the original reply of the Szeto. There are many ways to detect IE, it is not necessary to use this kind of kinky technique, the original reply, and the other method of Stu

if (!window.            VBArray) {alert ("not IE");            } else{alert ("IE"); }


Explanation of the world's shortest IE decision if (!+[1,])

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.