Just curious as to why isNaN('-10')
is false? I was thinking isNaN('-10')
should be true, but isNaN(-10)
should be false?
Does Javascript try to convert strings to numbers before applying isNaN
?
Just curious as to why isNaN('-10')
is false? I was thinking isNaN('-10')
should be true, but isNaN(-10)
should be false?
Does Javascript try to convert strings to numbers before applying isNaN
?
From MDN:
Since the very earliest versions of the isNaN function specification, its behavior for non-numeric arguments has been confusing. When the argument to the isNaN function is not of type Number, the value is first coerced to a Number. The resulting value is then tested to determine whether it is NaN.