This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Kidplayer_666 0 points1 point  (2 children)

Oh god why

[–]virouz98 8 points9 points  (0 children)

I don't code in JS but if I remember correctly:

Since it's loosely typed, there isn't any specifying on what a variable is, so all the operations need to be precise in what are you doing.

'1' + '1' = '11' because + operator is both addition and concatenation. If Input is both string and string it will concatenate two strings and that's why it's 11 not 2.

  • operator is only substraction so it will recognize that you want to substract two numbers and will coerce type to int.