Массив в массив (абстрактное сравнение равенства)
[x] == y;//false - why?
[x]
and y
do not refer to the same object. Arrays are objects and the ==
operator tests that they are the same object, not simply two objects having identical values for all properties. In order to determine object-equality in that way, you'll have to manually enumerate the properties of each object and test each value.
Согласно Алгоритм сравнения абстрактного равенства , используемый < a href = "http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.1" rel = "nofollow"> ==
:
Возвращает true, если x и y относятся к одному и тому же объекту. В противном случае верните false.
Строка в массив (абстрактное сравнение равенства)
x == y;//true - how ? oO
y
, an array, is coerced into a string because you used ==
when comparing it to x
, a string.
Согласно Алгоритм сравнения абстрактного равенства , используемый < a href = "http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.1" rel = "nofollow"> ==
:
Если тип (x) является либо строкой, либо номером, а тип (y) - объектом, возвращает
результат сравнения x == ToPrimitive (y).
Строка в массив (строгое сравнение равенства)
x === y;//fasle - okey
===
, unlike ==
, will not coerce y
into a string... so, you're comparing a string to an object.
Согласно Алгоритм сравнения строгого равенства , используемый < a href = "http://www.ecma-international.org/ecma-262/5.1/#sec-11.9.4" rel = "nofollow"> ===
:
Если Type (x) отличается от Type (y), верните false.