Odi's astoundingly incomplete notes
New entries | CodeWhy guessing is bad
Fine JavaScript example:
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 theobvious 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.
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
Add comment