Can the expression (a == 1 && a == 2 && a == 3) be true in JavaScript?
Hi everyone! I recently started learning JavaScript and came across a very strange puzzle. It checks whether the condition `(a == 1 && a == 2 && a == 3)` can ever be true. At first glance, this seems completely absurd — how can the same variable simultaneously equal three different numbers? If I write regular code:
```javascript
let a = 1;
console.log(a == 1 && a == 2 && a == 3); // false
```
Then, of course, I get false. But I've heard that JavaScript has some tricks with type coercion that can make such an expression true. I know that `==` (loose equality) can coerce types, but I still don't understand how this is possible.
Please explain, can this condition be made to work? If yes, how? And most importantly — why? Is this some kind of
No answers yet.
Log in to leave an answer