ParseInt(“08”) or “Why I hate JavaScript”

31 05 2011

Let’s do a little exercise. Let’s parse some numbers using JS.

ParseInt(“01”)
1

ParseInt(“02”)
2

ParseInt(“03”)
3

ParseInt(“04”)
4

ParseInt(“05”)
5

ParseInt(“06”)
6

ParseInt(“07”)
7

ParseInt(“08”)
0 (What?)

ParseInt(“09”)
0 (Wait, what!?!)

ParseInt(“10”)
10

Since Javascript uses Octal to parse numbers and starts at zero, 08 and 09 does not exist. They are therefore converted to zero. I found this out the hard way and spent a few hours pulling my own hair in frustration. My logic seemed squeaky clean and I didn’t suspect the parsing had given up on me.

The fix to this is to write:

ParseInt(“08”, 10)
8

Happy coding!

 

1257570397874





WP7 Talks Back to Me

8 10 2010

After receiving the Windows Phone 7 device I’ll be using in tomorrow’s presentation, I decided to try out the basic functionalities of the device. I tried calling my girlfriend by using the voice command “Call Caroline”. A woman’s voice asked me; “Caroline, home or mobile?”, I answered that I wanted to call her mobile. The phone-woman then said in a snarky tone: “Next time, you could just say, Call Caroline Mobile”. I wasn’t used to my phone talking back to me. Feels a bit Animatrix/Bladerunner. I’d better sleep with one eye open.

baltar-and-six

Digg This