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

Is it ever possible that (a ==1 && a== 2 && a==3) could evaluate to true, 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? →

Elsewhere , ,

One Response to Can (a ==1 && a== 2 && a==3) ever evaluate to true?

  1. Šime Vidas says:

    A more accurate title would be “20+ ways to make (a ==1 && a== 2 && a==3) evaluate to true in JavaScript” 😂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.