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
  • 719
  • 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
  • 12,158
  • 7
  • 41
  • 68
Nikita Shaposhnik
  • 997
  • 10
  • 13