If you accept user input from a text box, that input is a string. If the textbox is meant to collect a number, it would be easier to use == to compare as you get the string coerced (or is the number is coerced?). So cleaner code.
==
This is interesting. My gut reaction is that you should convert to the correct type ASAP, so you don't have to do it multiple times later.
But maybe the comparison before conversion is good so that you don't convert values you aren't going to use?
Still, I would do a comparison with ===, using a string representation of the number, rather than comparing to a number if that's the case.
===
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
If you accept user input from a text box, that input is a string. If the textbox is meant to collect a number, it would be easier to use
==to compare as you get the string coerced (or is the number is coerced?). So cleaner code.This is interesting. My gut reaction is that you should convert to the correct type ASAP, so you don't have to do it multiple times later.
But maybe the comparison before conversion is good so that you don't convert values you aren't going to use?
Still, I would do a comparison with
===, using a string representation of the number, rather than comparing to a number if that's the case.