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

in js •  7 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;)

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

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