[]==![] 解析过程

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值