-2

Here is the code:

alert(typeof(+"13t"));
alert(1 + (+"13t"));

Why in the first line the output is "number" And in the second line the output is "NaN"??

Experimenter
  • 1,607
  • 15
  • 22

2 Answers2

6

The value NaN is a number. Even though NaN means "not a number", it's still got the data type "number".

The string "13t" when coerced to a number value yields NaN, unsurprisingly. Adding 1 to NaN also yields NaN.

Pointy
  • 389,373
  • 58
  • 564
  • 602
3

That is because

typeof NaN; //outpute "number"

and

+"13t" //is NaN

And second one is trying to add 1 to NaN, which is still NaN.

gurvinder372
  • 64,240
  • 8
  • 67
  • 88