The ==
operator is really funny. It is usually doesn't behave as one think it will.
This led me to investigate exactly what is happening below the tip of the iceberg, and according to MDN it is as follow:
If the two operands are not of the same type, JavaScript converts the operands then applies strict comparison. If either operand is a number or a boolean, the operands are converted to numbers if possible; else if either operand is a string, the other operand is converted to a string if possible. If both operands are objects, then JavaScript compares internal references which are equal when operands refer to the same object in memory.
So, why doesn't "undefined" == undefined
evaluate to true?
Shouldn't undefined
be converted to "undefined"
and then return true according to this description?
typeof ("" + undefined)
undefined => ""
and the comparison then is"undefined" vs. ""
+
and for==
are different. Read starting at page 80 in the 5.1 spec.