首页 > 代码库 > []==![] 解析过程
[]==![] 解析过程
1. !优先级高于== 所以先执行![].
根据标准:
The production UnaryExpression : !
UnaryExpression is evaluated as follows:
Let expr be the result of evaluating UnaryExpression.
Let oldValue be ToBoolean(GetValue(expr)).
If oldValue is true, return false.
Return true.
![] 相当于 false;此时 []==![] 等价于 []==false
2. []==false;
根据标准:
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).
此时, []==false 等价于 []==0;
3.[]==0;
根据标准:
If Type(x) is either String or Number and Type(y) is Object,
return the result of the comparison x == ToPrimitive(y).
ToPrimitive : http://es5.github.io/index.html#x9.1
如果 最终 []==0 等价于 ""==0;
4.""==0;
根据标准:
If Type(x) is String and Type(y) is Number,
return the result of the comparison ToNumber(x) == y.
根据 ToNumber() http://es5.github.io/index.html#x9.3
"" 被转成0
此时 ""==0 等价于 0==0;
返回true
[]==![] 解析过程