Why does JavaScript handle the plus and minus operators between strings and numbers differently?

String concatenation is done with + so Javascript will convert the first numeric 1 to a string and concatenate “1” and “1” making “11”.

You cannot perform subtraction on strings, so Javascript converts the second “1” to a number and subtracts 1 from 1, resulting in zero.

Leave a Comment