What is the difference between != null and !== null?
This question already has an answer here:
The answer to the specific question about whether there's ever a case where !=
and !==
comparisons involving null
get different answers is yes :
undefined != null // false
undefined !== null // true
The rules for ==
and !=
explicitly include a clause that stipulates that null
and undefined
are the same.
Personally — that is, in my code — that fact is a reason for using !=
(or ==
) when checking for null
in cases where undefined
should be treated the same way (which is a pretty common situation).