Search code examples
javascriptoperatorsstring-concatenationconsole.log

Plus Concatenation String operator in JavaScript


I came across the scenario trying with different operating concatenations. I am wondering how this condition was working for the 2nd statement.

  1. console.log("10"+9); // 109

  2. Console.log("10"-9); //1

Can Someone tell me what's happening here?


Solution

  • + is used for both string concatenation and addition. If either operand is a string, concatenation is used. - is only used for subtraction, both operants are always coerced to numbers.