developer-plus / interview

https://interview.developer-plus.org
MIT License
9 stars 1 forks source link

Can (a==1 && a==2 && a==3) ever evaluate to true? #26

Open likui628 opened 2 years ago

likui628 commented 2 years ago

Is it ever possible that (a== 1 && a ==2 && a==3) could evaluate to true in JavaScript?

luckept commented 2 years ago

of course, my old baby!

const a = { val: 1 };
a[Symbol.toPrimitive] = () => a.val++;
console.log(a == 1 && a == 2 && a == 3);