I am trying to implement some javascript in my website but have gotten a problem when checking if a user input is a number. For example when passing "r"
into parseInt()
or parseFloat()
the result in the console is NaN
as expected. But when comparing NaN
and ParseInt("r")
the result is false (they are not the same) when I would've expected the comparison to return true
code and console output
console.log(parseInt("r"), parseInt("r") === NaN)
NaN false
console.log(parseFloat("r"), parseFloat("r") === NaN)
NaN false