16

var a = {
value: -1,
toString: function() {
return ++this.value;
}
}

if(a & !a) {
console.log("F**k you JS!");
}

if(a == 2 && a == 3) {
console.log("F**k you again JS!");
}

Comments
  • 2
    JS is a wonderful language. Don't like it — don't use it.
  • 1
    @ruant 🤣

    At least, I'm hoping it's you that mentioned JS in Slack the other day. Otherwise this is a wrong tag 😔
  • 0
    A variant of this is apparently a popular question in JS interviews.
  • 3
    Every time you compare it, it calls `toString` and increments `value`

    Makes perfect sense...
  • 1
    i dont see why you would hate on the fact that the code you wrote is straight up dumb. languages like ruby, elixir, and pretty much every other language has some type of method override for objects, so you couldve done this in basically any other language.
  • 0
    @itsdaniel0 Me me me! :D
Add Comment