Example without getters or valueOf:
a = [1,2,3];_x000D_
a.join = a.shift;_x000D_
console.log(a == 1 && a == 2 && a == 3);
_x000D_
This works because ==
invokes toString
which calls .join
for Arrays.
Another solution, using Symbol.toPrimitive
which is an ES6 equivalent of toString/valueOf
:
let i = 0;_x000D_
let a = { [Symbol.toPrimitive]: () => ++i };_x000D_
_x000D_
console.log(a == 1 && a == 2 && a == 3);
_x000D_