I try to understanding the expression {} == true following the section 7.2.12 of doc Ecma-262.
- If Type(y) is Boolean, return the result of the comparison
x == ToNumber(y)
The result of ToNumber(true) is 1, then
{} == 1
- If Type(x) is Object and Type(y) is either String, Number, or Symbol, then return the result of the comparison
ToPrimitive(x) == y.
I am confused at the ToPrimitive({}) now.
If hint is "string", then
a. Let methodNames be «"toString", "valueOf"».
Else,
a. Let methodNames be «"valueOf", "toString"».
Should ToPrimitive({}) be interpreted as {}.toString() or {}.valueOf()?
Suppose the toString() is called.
If Type(x) is String and Type(y) is Number, return the result of the comparison
ToNumber(x) == y
So {} == true could be ToNumber(ToPrimitive({})) == ToNumber(true)?