By doing a proper comparison:
x === y && y === z
// due to transitivity, if the above expression is true, x === z must be true as well
x==y==z
is actually evaluated as
(x == y) == z
i.e. you are either comparing true == z
or false == z
which I think is not what you want. In addition, it does type conversion. To give you an extreme example:
[1,2,4] == 42 == "\n" // true
The problem is that when x==y
and z==1
, x==y==z
will return true.
Yes, because x == y
will be true
, so you compare true == 1
. true
will be converted to the number 1
and 1 == 1
is true
.