Here javascript should do for === :
- If Type (x) is different from Type (y), return false.
- If type (x) is Undefined, return true.
- If Type (x) is Null, return true.
- If Type (x) is Number, then
- If x is NaN, return false.
- If y is NaN, return false.
- If x is the same value as y, return true.
- If x is +0 and y is -0, return true.
- If x is -0 and y is +0, return true.
- Returns false.
- If Type (x) is String, then return true, if x and y are exactly the same sequence of characters (same length and same characters in corresponding positions); otherwise return false.
- If Type (x) is boolean, return true if x and y are both true or both false; otherwise return false.
- Returns true if x and y refer to the same object. Otherwise, return false.
And here is what it should do for == :
- If type (x) matches type (y), then
- If type (x) is Undefined, return true.
- If Type (x) is Null, return true.
- If Type (x) is Number, then
- If x is NaN, return false.
- If y is NaN, return false.
- If x is the same value as y, return true.
- If x is +0 and y is -0, return true.
- If x is -0 and y is +0, return true.
- Returns false.
- If Type (x) is String, then return true, if x and y are exactly the same sequence of characters (same length and same characters in corresponding positions). Otherwise, return false.
- If Type (x) is boolean, return true if x and y are both true or both false. Otherwise, return false.
- Returns true if x and y refer to the same object. Otherwise, return false.
- If x is null and y is Undefined, return true.
- If x is undefined and y is null, return true.
- If Type (x) is Number and Type (y) is String, return the result of the comparison x == ToNumber (y).
- If Type (x) is String and Type (y) is Number, returns the result of the comparison ToNumber (x) == y.
- If Type (x) is boolean, return the result of the comparison ToNumber (x) == y.
- If type (y) is boolean, return the result of the comparison x == ToNumber (y).
- If Type (x) is a string or number, and Type (y) is Object, returns the result of the comparison x == ToPrimitive (y).
- If Type (x) is Object and Type (y) is either String or Number, returns the result of the comparison ToPrimitive (x) == y.
- Returns false.
Note that if Type(x) is equal to Type(y) , then the operators do the same thing. However, if this is not the case, then == may have to perform various conversions, whereas === simply returns false.
For the links you specified, the types that are compared are actually the same, so the two operators should work roughly the same. The differences here will be based on implementation details - since they do different things, they can be optimized in different ways. Theoretically, since === does less, one would think that it would always be faster, but it does not look like some Firefox builds, at least if these tests are accurate.
However, see the difference if the types are different . When you execute "hi" === {} you get ~ 66 million op / sec, but for "hi" == {} you only have ~ 4 million op / sec.
Claudiu
source share