DEV Community

Discussion on: '1' - '1' / 2 = ? , Can you find the answer ?

Collapse
 
miketalbot profile image
Mike Talbot ⭐ • Edited

If there is a numerical operation then the string is converted into a number. The + is a string concatenation operator and a numerical operator, string wins in this case. So "1" concatenate the result of 1*2 = 2 becomes "12" as a string.

Note that + on its own is always a numerical operator which is why you might see this:

function add(a,b) {
   return +a + +b
}
Enter fullscreen mode Exit fullscreen mode

The +a is bound to convert a to be a number (if possible) etc.