'Is there an operator for comparing undefined or null types?

Sorry if the title made it unclear, but I've been wondering, is there an operator for comparing types like null and "null"?
We all know that:
"1" == 1 returns true.
and
"1" === 1 returns false.
But when I try to do something like:
undefined == "undefined", for me, it returns false, even though I am not using ===.
Why does this occur? Is there an operator for comparing undefined and "undefined", or null and "null"?, etc...



Solution 1:[1]

In answer to the question in the title, no there isn't - JavaScript does not generally examine the semantic content of strings - "use strict" placed at the beginning of code to invoke strict mode execution is the exeception.

Note that the typeof operator is a convenience operator which does not return the data type of its operand in all cases - function objects are of (JavaScript) data type "Object", and null is of (JavaScript) data type "Null".

"undefined" is a string value with specific content. It is not equal to undefined (the one and only value with data type "Undefined") or null (the one and only value with data type "Null").

There is however an automatic type conversion between null and undefined which causes the non-strict equality operator to treat them as being equal, often used with a negation operator:

 if( value != null) {
     // proceed knowing value isn't `undefined` or `null
 }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 traktor