Arithmetic Operators

Top  Previous  Next

Operators:  +  -  *  /  %

Syntax:

expression1 + expression2

addition or string concatenation

expression1 - expression2

subtraction

expression1 * expression2

multiplication

expression1 / expression2

division

expression1 % expression2

modulo

 

The + operator performs string concatenation if either of its expressions are strings. In this case, the other expression is converted to String if necessary.

 

Otherwise, both expressions are converted to Number. If either expression is NaN, the result is NaN. The division operator / always converts both expressions to internal floating-point format. All other operators use integer format if both expressions are integer, or floating-point format if not.

 

The modulo operator % computes the remainder of division. Mathematically, x % y computes n = x / y and truncates n to an integer. Then the result of the operator is x - (y * n).