What happens when we try to add a number to undefined value?


If you try to add a number to undefined value then you will get a NaN. The NaN defines Not a Number. Following is an example −

Case 1

var anyVar=10+undefined;
print(anyVar) //Result will be NaN

Case 2

var anyVar1=10;
var anyVar2;
var anyVar=yourVar1+yourVar2;
print(anyVar) //Result will be NaN

Case 1

Let us implement the above cases. The query is as follows −

> var result=10+undefined;
> print(result);

This will produce the following output −

NaN

Case 2

Let us implement the above case −

> var value;
> var value1=10;
> var result=value1+value
> result

This will produce the following output −

NaN

Updated on: 14-May-2020

524 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements