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

in #js7 years ago

Wow, Javascript, so powerfull..

Following this Stackoverflow question:

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

And the answer is .. yes..

const a = {
  i: 1,
  toString: function () {
    return a.i++;
  }
}

if(a == 1 && a == 2 && a == 3) {
  console.log('Hello World!');
}

Thank you , loose equality operators.
Not sure, if it is used as intended;)

Sort:  

This post has been upvoted by @microbot with 9.0%!
Vote for my creator @isnochys as witness!

Coin Marketplace

STEEM 0.13
TRX 0.24
JST 0.032
BTC 83868.39
ETH 2101.34
USDT 1.00
SBD 0.63