-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
  • 2,084
  • 1
  • 19
  • 26

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
  • 405,095
  • 59
  • 585
  • 614
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
  • 66,980
  • 10
  • 72
  • 94