Mega Code Archive

 
Categories / JavaScript Tutorial / Operators
 

Arithmetic Operators (+)

All the common arithmetic operators will attempt to convert strings to numbers when applicable. If a string cannot be converted to a number, NaN (Not A Number) will be returned. Addition (+) If the values on either side are numerical values, the values are added together. IF the values are strings, they are concatenated together. The following line of code var resultOfAdd = 34 + 12; would set the variable resultOfAdd equal to 46 var resultOfAdd = "a" + "b"; would set the variable resultOfAdd equal to the string "ab".