日期:2014-05-16  浏览次数:20421 次

[]==[]输出ture或者false? []==![]输出ture或者false?
[]==[]输出ture或者false? []==![]输出ture或者false?

js中 

![]是flase的意思?
求大神解释

------解决方案--------------------
因为:false、0、null、 NaN、'' 为 false其他均为true
推论:typeof [] == 'object' && [] !== null
所以:Boolean([]) = true
所以:!Boolean([]) = false

[] == ![]
[] == false
Number([]) == 0
0 == false => true

ECMA-262
The comparison x == y, where x and y are values, produces true or false. Such a comparison is performed as follows:
1.If Type(x) is the same as Type(y), then
a.If Type(x) is Undefined, return true.
b.If Type(x) is Null, return true.
c.If Type(x) is Number, then
i.If x is NaN, return false.
ii.If y is NaN, return false.
iii.If x is the same Number value as y, return true.
iv.If x is +0 and y is ?0, return true.
v.If x is ?0 and y is +0, return true.
vi.Return false.
d.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.
e.If Type(x) is Boolean, return true if x and y are both true or both false. Otherwise, return false.
f.Return true if x and y refer to the same object. Otherwise, return false.
2.If x is null and y is undefined, return true.
3.If x is undefined and y is null, return true.
4.If Type(x) is Number and Type(y) is String, return the result of the comparison x == ToNumber(y).
5.If Type(x) is String and Type(y) is Number, return the result of the comparison ToNumber(x) == y.
6.If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.
7.If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).
8.If Type(x) is either String or Number and Type(y) is Object, return the result of the comparison x == ToPrimitive(y).
------解决方案--------------------
[]==[]输出ture或者false?
true

[]==![]输出ture或者false?

false


------解决方案--------------------
[]是空数组字面量,转换成boolean值为true。