In JavaScript,
1 + "1" = 11
But,
1 - "1" = 0
Here is why ↓
1 + "1" = 11
But,
1 - "1" = 0
Here is why ↓
→ In computer programming, Concatenation, in the context of programming, is the operation of joining two strings together. The term"concatenation" literally means to merge two things together.
→ Similarly in JavaScript, The + is a concatenation operator for strings. Therefore the number is subsequently transformed into a string and concatenated as a result.
→ To make it more clear, The + operator in Javascript (as in many other languages) has two different Jobs: It acts as an addition operator, and as a string concatenation operator. In our case, the concatenation takes precedence over the addition of numbers.
→ However, the 2nd case is called concatenation. The "-" is only for numeric, both operands are converted to numeric and thus give a numeric answer.
Loading suggestions...