Is it ever possible that
(a ==1 && a== 2 && a==3)
could evaluate totrue
, in JavaScript?This is interview question asked by a major tech company. My answer was that it’s impossible. They said nothing is impossible. It happened 2 weeks back, but I’m still trying to find the answer. I know we never write such code in our day to day job, but I’m curious.
Betteridge’s Law of Headlines demands the answer to this question to be no, but given the fact that it’s question about JavaScript the answer – of course – is yes.
Here’s a hint: note the ==
that’s used, allowing for coercion to happen 😉
StackOverflow: Can (a ==1 && a== 2 && a==3)
ever evaluate to true? →
A more accurate title would be “20+ ways to make (a ==1 && a== 2 && a==3) evaluate to true in JavaScript” 😂