+ is a string concatenation operator in Javascript. PHP and Javascript, both of which are freely typed languages, deal with conflicts between adding and concatenation in different ways. PHP deals with it, having a completely separate statement (as you said . ). Javascript does this by having specific rules for which the operation is performed. For this reason, you need to know if your variable is being dialed as a string or number.
Example:
"1" + "3" : In PHP, this is equal to the number 4. In JavaScript, this is equal to "13". To get the desired 4 in Javascript, you would do Number("1") + Number("3") .
The main idea in Javascript is that any two variables that are typed as numbers with the + operator between them will be added. If either a string, it will be concatenated.
source share