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
  • 41,793
  • 59
  • 191
  • 359

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
  • 914,110
  • 126
  • 1,211
  • 1,335
2

isNaN implicitly converts to Number type. Link

Tushar Shahi
  • 16,452
  • 1
  • 18
  • 39