[1815840 views]

[]

Odi's astoundingly incomplete notes

New entries | Code

Why guessing is bad

Fine JavaScript example:

alert(parseInt("08"));

yields 2 on FireFox 3.5, 0 on IE8 and Chrome, and 8 on Opera.

Background: parseInt interpretes a number with a leading zero in octal (not decimal). 08 is not a legal octal value however.

The problem here is not so much that all platforms behave differently. But that none of them actually spots the obvious error and throws an exception. So all the implementations just make a wild guess and return a wrong value (any value is wrong for an invalid input)! This is bad for the developer as it prevents bugs from being discovered.


posted on 2009-07-01 16:24 UTC in Code | 0 comments | permalink