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!