I've been programming an Intranet site for the company I work for and have come across a very interesting javascript bug. Most people will never run into this problem, but if you do, here is the bug and a work-around I've come up with.

The bug is this:

If you try and parseInt a string number of either 08 or 09, it will return a value of 0 instead of 8 or 9. If you try any other number (01 - 07), it will return the proper number (e.g. parseInt("01") will return 1, not 0).

But the thing is, is that if you just have "8" or "9" without the zeros, it will parse the string correctly.

Try it out for yourself...

Code:
<html>
<head>
<script language="javascript1.5" type="text/javascript">
var calendar_month = "08" //change this number to 01-07 or to 8 or 9 to work, 08 & 09 do not
var test = parseInt(calendar_month)
alert("parsed date is " + test + " and the Non-parsed date is " + calendar_month);
</script>
</head>
<body>

</body>
</html>
In this example, I was trying to parse a user inputed month so I could compare it to the current date. The month date is recognized as a string so I had to convert it to a number for my function to work. The work around I found is to put an if...else function to check to see if the string was a 08 or 09 and if so, to change the variable that held month value to just 8 or 9.

Code:
<script language="javascript1.5" type="text/javascript">
var calendar_month = "08" //change this number to 01-07 to work, 08 & 09 do not
if (calendar_month == "08") calendar_month = "8";
if (calendar_month == "09") calendar_month = "9";
var test = parseInt(calendar_month)
alert("parsed date is " + test + " and the Non-parsed date is " + calendar_month);
</script>
This works all fine and dandy. The only problem with this work-around is that this bugs "works???" no matter how many zeros are in front of an 8 or 9, (0000008 will bug out the same as 08). So if you have a situation where you may have more then 1 zero in front, and you don't know how many, you will have to build a more complex checker.

As I said, 99% of you will never need to know this, but if you ever do, here it is.

I don't know if there are any other combinations that causes this bug. I only know of the 08 and 09. I checked it with IE 5.5, NS4.7 and NS6. All reproduce the same bug every time.