Java Script Arithmetic Operators
By Stephen Bucaro
Java Script arithmetic operations are represented by normal mathematical notation as shown below.
Addition
var n = 13 + 24;
Subtraction
var n = 24  13;
Multiplication
var n = 12 * 5;
Division
var n = 12 / 4;
In each case above, the result of the arithmetic operation is assigned to the variable n.
There are several mathematical operators that you may not be familiar with.
Negation
The negation operator () returns the same result as multiplying the value by 1.
var m = 5;
var n = n;
In the example above, a value of 5 is assigned to the variable n.
Modulus
The modulus operator (%) returns the remainder of a division rather than the quotient.
var n = 13 % 5;
In the example above, a value of 3 is assigned to the variable n.
Increment and Decrement
The increment operator (++) increases a value by one.
var n = 3++;
In the example above, a value of 4 is assigned to the variable n.
The decrement operator () decreases a value by one.
var n = 3;
In the example above, a value of 2 is assigned to the variable n.
