undefined : Th-is can act as both a type and a value. A variable that has been declared and has not been assigned with a value is undefined always.
For example –
var tmp; // just declared, not assigned with a value
console.log(tmp) ; ———————-> undefined
console.log( typeof tmp );———————-> “undefined”
From this it is clear that value of tmp is undefined. and its type also is undefined. but this is an undefined enclosed by quotes.
console.log(a); —————————-> null
console.log( typeof a ); ———————-> Object
Still there will be some confusion for some of you. I had undergone this phase. So I would like to summarize it as follows.
NaN (Not a Number)
It is the value returned as a result when an invalid arithmetic operation is performed. Its type is Number. It is value.
For example :
var tmp = 10 / ten // invalid arithmetic operation
console.log(tmp) —————————> NaN
Now we need to understand another important concept about NaN ………………….
Two NaNs are not at all equal in normal comparisons!!!!!!!
This would be clear from the following example.
var tmp2 = 10 / ten // invalid arithmetic operation
console.log(tmp2) —————————> NaN
if (tmp == tmp2) ——————————–> false
Normally what we are expecting for above operation , is a true value. But Its result is false. But What if we need to compare two NaN values? For that purpose we need to make of the built in method isNaN() . It returns a true value when a NaN value is fed as an input.
For example, in the previous cases we have seen
isNaN(tmp) ——————————> true
isNaN(tmp2) ——————————-> true
For comparing these two NaNs
if ( isNaN(tmp) && isNaN(tmp2) ) ——————————> true
Now we can compare two NaN values successfully.