Strange results of parseInt explained
Method parseInt outputs strange results when we try to convert certain strings that begin with "0".
parseInt("08") //=> 0
parseInt("09") //=> 0
The reason of it is that method parseInt tries to guess the base of numeric system. It incorrectly assumes octal base here.
However the base of the number can be specified as a second parameter:
parseInt("08", 10) //=> 8
parseInt("09", 10) //=> 9
Written by Tomasz Noworyta
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Related Tags
#javascript
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#