[] ==![]计算结果为true [英] [] == ![] evaluates to true
问题描述
我想知道为什么标题中给出的表达式
I would liketo know why the expression given in the title
[] ==![]
被计算为true。
不能将数组作为字符串进行比较。我明白了。如果
You cannot compare arrays as strings. I get that. If
[] == []
将评估为false,因为引用不同。虽然如果我们有以下语句。
will evaluate to false because the references are different. Though if we have the following statement.
var arr = [];
arr == arr // this evaluates to true simply because references are the same.
按顺序A == B返回true A和B必须为false或true。
A ==!B为了返回真A可以是真的,B可以是假或反之亦然,但在这种情况下A和B是相同的值,所以我不能得到它。
In order A == B to return true either A and B have to be false or true. A == !B in order to return true A can be true and B can be false or vice versa but in this case A and B are the same values so I don't get it.
推荐答案
![]
计算为 false
因为引用是真的。 []
可以转换为falsey的数字(在这种情况下为0)。因此:条件通过相等。如果你 ===
它会是false。
![]
evaluates to false
because the reference is truthy. []
can be converted to an number (0 in this case) which is falsey. Therefore: the condition passes as equal. If you did ===
it would be false.
这篇关于[] ==![]计算结果为true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!