News for hackers. Stuff that matters.
Re:Why does parseInt(1/0, 19) return 18? by JonoW on Tuesday July 10, 2012 @02:40AM (#4222438)
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.
Re:Why does parseInt(1/0, 19) return 18? by saurik on Tuesday July 10, 2012 @02:49AM (#4222465)
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.)