parseInt gotchas


Debugging an application today before launch I noticed a problem where it seemed to be parsing a specific time value (0900) incorrectly as (12:00 AM or ‘0000’). ┬áDuring my search I ran across this oddity with the parseInt function of Javascript.

Apparently parseInt can also work with different base notations so it’s a good idea to specify base 10 in the manner parseInt(val,10) just to be safe if you are passing it numbers (such as time values) that may start with a zero and you don’t want invalid octal numbers (like 09) parsing to zero.

No related content found.

Share

Leave a comment