(picture)

August 04, 2002

parseInt

I was hit by a weird JavaScript-related bug: parseInt(n) returned zero, when n was a plainly numeric string.

Turns out, n was "08". And any string beginning with a zero is treated by parseInt as octal! Rather than throwing an exception, jscript just throws the 8 away. Is octal really used, anywhere (except Unix file permissions)?

Two lessons from this:

  1. parseInt(n,10)
  2. Octal should have been killed thirty years ago...