Skip to main content

Strings and Number, Arithmetic Operators

The + (Addition) operator is used for both addition and string concatenation; numbers are added, strings are concatenated (Specifications: ECMAScript Language). Therefore, if one of the operands of the addition is a string, the result will be a string.

Examples

'a' + 10

The result will be the string 'a10''.

20 + 10

The result will be number 30.

All other arithmetic operators */-@ (multiplication, division, subtraction and remainder) support numeric strings. Meaning, that if one of the operands is a numeric string, it will be automatically be converted to a number.

'1'+10

The result will be the string '110' .

20 /'10'

The result will be the number 2,

20 /'a'

The result will be Undefined.

info

Remember that addition operator concatenates strings

'my' + 10

The result will be the string 'my10'.