Let’s start exploring null and undefined by having a look at the following comparisons:
null >= 0; //true null <= 0; //true null == 0; //false null > 0; //false null < 0; //false
How can null be bigger or equal to zero, less or equal to zero, but not be equal to zero?!
Equality operators compare at an object level. If both _operands, _the things left and right of the operator, are of different types a strict comparison (=== or !==) is used. Because null is an object and 0 is a number they are not equal.
Number(null) >= 0; //true
Which makes much more sense. Number(null) return the value 0 and 0 is equal to 0.
Let’s try the same examples with undefined:
undefined >= 0;//false undefined <= 0;//false undefined == 0;//false undefined < 0;//false undefined > 0;//false
There’s even a little bit more to the _comparison algorithm _than this, but this explains the idea.
For example in a function retrieving a piece of data. When that data isn’t there, this function returns null. Otherwise, it returns the data. This way one can tell if the value is returned by the function and is set to null or if the variable that should contain the result isn’t set at all.
In other words: null !== undefined