var i = 2;
Number.prototype.valueOf = function () {
return i++;
};
var a = new number (42);
if (a = = 2 && A = = 3) {
Console.log ("Yep, this happened.");
}
============================
"0" = = NULL; False
"0" = = undefined; False
"0" = = false; True--UH oh!
"0" = = NaN; False
"0" = = 0; True
"0" = = ""; False
false = = NULL; False
false = = undefined; False
false = = NaN; False
false = = 0; True--UH oh!
false = = ""; True--UH oh!
false = = []; True--UH oh!
False = = {}; False
"" = = null; False
"= = undefined; False
"" = = NaN; False
"= = 0; True--UH oh!
"" == []; True--UH oh!
"" == {}; False
0 = = NULL; False
0 = = undefined; False
0 = = NaN; False
0 = = []; True--UH oh!
0 = = {}; False
[] == ! []; True
2 = = [2]; True
"" = = [NULL]; True
0 = = "\ n"; True
var a = null;
var B = Object (a); Same as ' Object () '
A = = B; False
var c = undefined;
var d = Object (c); Same as ' Object () '
c = = D; False
var e = NaN;
var f = Object (e); Same as ' new number (e) '
E = = f; False
======================================================
Explanation in the ES5 specification:
Comparing:objects to Nonobjects
If an object/function/array are compared to a simple scalar primitive
(string, number, or Boolean), the ES5 spec says in clauses
11.9.3.8-9:
1. If Type (x) is either a String or number and Type (y) is Object,
Return the result of the comparison x = = Toprimitive (y).
2. If Type (x) is an Object and Type (y) is either String or number,
Return the result of the comparison toprimitive (x) = = Y.
Comparing:nulls to Undefineds
Another example of implicit coercion can be seen with = = Loose
Equality between null and undefined values. Yet again quoting the
ES5 spec, clauses 11.9.3.2-3:
1. If x is null and y is undefined, return true.
2. If x is undefined and y is null, return True.
Comparing:anything to Boolean
1. If Type (x) is Boolean, return the result of the comparison
Tonumber (x) = = Y.
2. If Type (y) is a Boolean, return the result of the comparison x = =
Tonumber (y).
Comparing:strings to Numbers
1. If Type (x) is number and Type (y) is String, return the result of
The comparison x = = Tonumber (y).
2. If Type (x) is a String and Type (y) is number, return the result of
The comparison tonumber (x) = = Y.
============================== Intuitive Comparison Chart
http://dorey.github.io/JavaScript-Equality-Table/
Do you really understand the = = equals operator in JavaScript?