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

MongoDBDatabaseBig Data Analytics

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
raja
Published on 14-May-2020 08:39:54
Advertisements