Today I learned that the isNaN
global function in javascript isn’t very useful for validating numbers.
The main reason is that it returns false
for an empty string since it coerces it to 0
.
To add to the confusion, Number.isNaN()
behaves slightly differently since it just checks for the value NaN
.
For validation, I found Number.isInteger()
to be the most useful.