0

Well,I am going through Mozilla Javascript Reference and found that..

isNaN(1 + null) //false
isNaN(1 + undefined) //true

I am not able to understand reason behind this.

mukesh kudi
  • 709
  • 6
  • 20

1 Answers1

6

From https://www.w3schools.com/js/js_type_conversion.asp, , when null is converted to number, it becomes 0. Therefore, 0 + 1 = 1, it's valid number, so isNaN returns false.

When undefined is converted to Number, it becomes NaN. Any Number + NaN = NaN, so isNaN return true.

Sagar V
  • 11,606
  • 7
  • 43
  • 64
Nikita Shaposhnik
  • 967
  • 10
  • 13