I chose to add the word "probably" because I wasn't 100% sure, that it is still a "no-exception".
I explained the asker that the problem with the comparison was (unless anything have changed -see above) that the script compared strings and not numbers, and that to convert the data into a number was done, and is most cases sufficiently, by multiplying by 1.
And I am pretty sure, that the asker understood it that way.
Sheesh. Look, I always treat any question as a learning experience for the one who asked it.
Yes, you solved his problem.
But the next time he has a similar problem, he's liable to come back and get another answer. UNLESS he understands the cause of the problem.
And the reason I prefer parseFloat is simple: It will give me a NaN value that I can test for and then I can popup an alert or whatever to tell the user to correct his/her input. Could I do the same by multiplying by 1? Okay, I guess so. But in any case, I would probably advice the person asking the question to test for a number before *assuming* that it's valid.
Notice my user name: OldPedant. Okay, I readily admit the name fits. Somebody tagged me with it once, and it stuck. However, I'll make an effort to remember your username and not comment on your posts.
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
However, I'll make an effort to remember your username and not comment on your posts.
That's not what i asked for!
That you comment on my posts, is not an issue itself.
But when we are going help newbies or less experienced, I think we must teach them at their level, not ours.
A little like in highschool:
If they have problems with multiplication, then trying to teach them about combinations, permutations, or maybe integrals and complex numbers, would be nothing but nonsense to them. even factorials would.
Of course he can always google "parseFloat" to see what that build-in function actually does.
Mostly you can see what level they are by the type of issue that they have, and the way they ask, and then it up to us to try to match our teaching with that level.
And correcting each other at a more advanced level, could cause confusion instead of solution.
I admit I remember trying to help a woman in Australia learn ASP coding. I tried for maybe 3 years. And by the end of the second year, she was still asking the same questions she did at the very first. She simply was incapable of learning the concepts involved. So for the last year I gave up and just answered questions.
Still, I always keep hoping that even newbies are capable of learning the concepts.