Java Script Syntax - Operators

Operators

The '+' operator is overloaded: it is used for string concatenation and arithmetic addition. This may cause problems when inadvertently mixing strings and numbers. As a unary operator, it can convert a numeric string to a number.

// Concatenate 2 strings alert('He' + 'llo'); // displays Hello // Add two numbers alert(2 + 6); // displays 8 // Adding a number and a string results in concatenation alert(2 + '2'); // displays 22 alert('$' + 3 + 4); // displays $34, but $7 may have been expected alert('$' + (3 + 4)); // displays $7 // Convert a string to a number alert(+'2' === 2); // displays true alert(+'Hello'); // displays NaN

Read more about this topic:  Java Script Syntax