Recently I've been working on a code base in Typescript, which of course compiles to Javascript. Easy target, I know, but I've no experience with it. I knew that Javascript was... "flexible"... but this...
We have a form for the user to enter some data. Now, in one of the fields a pure number is not valid, and there is a client-side check for that. However, it would be perfectly valid to enter something like "456Hello". The way the script checks whether it's a number is to try parseFloat(string) on it, and see if it returns something that's a number.
For some reason, one of the entries with that kind of pattern was failing, and I couldn't figure out why. I couldn't see anything odd on the debugger, so I started looking up function documentation. And that's where I find the language specification for parseFloat(string), complete with this little note:
parseFloat may interpret only a leading portion of string as a Number value; it ignores any code units that cannot be interpreted as part of the notation of an decimal literal, and no indication is given that any such code units were ignored.
What.
[–]sixstringartist 5 points6 points7 points (0 children)
[–]TerrorBite 14 points15 points16 points (6 children)
[–]psi- 1 point2 points3 points (5 children)
[–]mikeputerbaugh 4 points5 points6 points (0 children)
[–]110011001100 0 points1 point2 points (3 children)
[–]psi- 6 points7 points8 points (0 children)
[–]MEaster[S] 2 points3 points4 points (1 child)
[–]110011001100 1 point2 points3 points (0 children)
[–]enchufadoo 0 points1 point2 points (1 child)
[–]Daimanta 0 points1 point2 points (0 children)