Hacker News new | ask | show | jobs
by JonoW 5092 days ago
One bit I think is poor design is that parseInt parses all characters until it finds a non numeric one. It can introduce some really subtle bugs.
1 comments

That was my potential complaint/fix #1: that parseInt could refuse to work if it is passed a string that contains things that aren't valid digits in whatever radix it is working in. I personally believe I agree with you, but this is actually the way these functions work in most languages. In particular, this is the behavior of the various functions in C, such as atoi and strtol. While this isn't then "best of breed" behavior, I don't think it is unreasonable behavior. (Python's int() does not do this, for what it is worth: it gets angry and throws an exception if you pass it something that isn't entirely a number.)