34

1 + 2 + 3 + 4 + 5 + “6”

Comments
  • 10
    Damn, this made me laugh
  • 7
    Wait, is this how it works? I’d think that it would be 15 + "6" = "156" because the + operators should be evaluated left to right.
    But then again, it’s JS, the teletubby of "programming languages". So, not really surprised.
  • 3
    Ah, type coercion at its finest.

    @Lensflare indeed in this sense, JavaScript is the Teletubby of programming languages 😂
  • 1
    If you write JavaScript like that, I don't want to be your friend.

    On a serious note, of course it's silly that it allows stuff like this, but then again the language was written in one week; moreover if they somehow change it to disallow things like this, it would break like 80% of the sites that are live right now.
  • 0
    @kamen of course nobody can expect that to change because it would break compatibility. But it’s nice to see people admitting that it is a horrible design rather than trying to justify it as something that makes JS awesome.
    And saying "It’s only bad because you don’t understand it 🤪".
  • 0
    @Lensflare actually that's the result
  • 1
  • 1
    @Lensflare doesn't actually matter, and only makes the point better: we are unsure and guessing which of the two stupid unexpected/unwanted/incorrect behaviors will happen =D
Add Comment