0

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?

Ole
  • 36,095
  • 47
  • 151
  • 295

2 Answers2

2

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.

Quentin
  • 857,932
  • 118
  • 1,152
  • 1,264
2

isNaN implicitly converts to Number type. Link

Tushar Shahi
  • 10,769
  • 1
  • 9
  • 29