O'Reilly logo
  • Ahmed Elgendy thinks this is interesting:

If you try to add a number and a string, JavaScript converts the number to a string and concatenates the two. Kind of the opposite of what it does with equality:

image with no caption

If you put the string first and then use the + operator with a number, the same thing happens: the number is converted to a string and the two are joined by concatenation.


Cover of Head First JavaScript Programming


What if you use + operator with two operands of two different types?