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"??
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"??
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
.
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
.