[]==![] 解析过程

1.  !优先级高于== 所以先执行![].

根据标准:

The production UnaryExpression : ! UnaryExpression is evaluated as follows:

  1. Let expr be the result of evaluating UnaryExpression.

  2. Let oldValue be ToBoolean(GetValue(expr)).

  3. If oldValue is true, return false.

  4. Return true.

  ![] 相当于 false;此时 []==![] 等价于 []==false

2. []==false;

根据标准:

  1. If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.

  2. If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).

 此时, []==false 等价于  []==0;

3.[]==0;

根据标准:

    1. 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;

根据标准:

    1. 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

  

原文地址:https://www.cnblogs.com/Mr-Joe/p/4237136.html