Friday, May 17, 2013

Internet Explorer version ≤8 parseInt() octal radix default

Old browsers, like IE7 and IE8 ( that uses ECMAScript older than 5) uses octal radix ( or base ) as default when parsing strings that start with “0” as ints. Internet Explorer 8 and older versions therefore have this rather peculiar default behavior.

parseInt(“01”) => 1*8^0 = 1
parseInt(“05”) => 5*8^0 = 5
parseInt("055") => (5*8^1)+(5*8^0), 40+5 = 45
parseInt(“07”) => 7*8^0 = 7

parseInt(“08”) => 0*8^0 = 0 (the 8 has no equivalent in base 8)
parseInt(“09”) => 0, same issue

parseInt(“10”) => (0*10^0) + (1*10^1) = 10 ( IE8 recognizes this as base 10, as it doesn’t start with zero.) 

Say that you're parsing months as ints, 01-12. 01-09 will be parsed as base 8, and 10-12 as base 10.
It'll work in all new browsers, but 08 and 09 will be parsed as zero in IE8 or older ( or other old browsers ).

Luckily, for us all, there is a way to specify which base to use.

parseInt(string,base);
parseInt(“08”,10) => 8*10^0 = 8

3 comments :

  1. Im no expert, but I believe you just made an excellent point. You certainly fully understand what youre speaking about, and I can truly get behind that. marketing1on1.com/professional-seo-services-company

    ReplyDelete
  2. thanks a lot for sharing this useful material. I don't use Internet Explorer as a browser at all. Nevertheless, I have heard some useful feedbacks about this browser at the article https://specialessays.com/business-essay/

    ReplyDelete
  3. we are happy if you call us so, Do not hesitate to call us if there is any query in your mind! We are here to help you.You can contact us at Write My Essay For Me Cheapin any part of the world as we deliver to native and non-native speakers of English language alike.

    ReplyDelete