Arithmetic Expressions
This section covers the operators that perform arithmetic or other numerical manipulations on their operands. The multiplication, division, and subtraction operators are straightforward and are covered first. The addition operator gets a subsection of its own because it can also perform string concatenation and has some unusual type conversion rules. The unary operators and the bitwise operators are also covered in subsections of their own.
The basic arithmetic operators are * (multiplication), / (division), % (modulo: remainder after division),
+ (addition), and - (subtraction). As noted, we’ll discuss the
+ operator in a section of its own.
The other basic four operators simply evaluate their operands, convert
the values to numbers if necessary, and then compute the product,
quotient, remainder, or difference between the values. Non-numeric
operands that cannot convert to numbers convert to the NaN value. If either operand is (or converts
to) NaN, the result of the
operation is also NaN.
The / operator divides its
first operand by its second. If you are used to programming languages
that distinguish between integer and floating-point numbers, you might
expect to get an integer result when you divide one integer by
another. In JavaScript, however, all numbers are floating-point, so
all division operations have floating-point results: 5/2 evaluates to 2.5, not 2. Division by zero yields positive or
negative infinity, while 0/0
evaluates to NaN: neither of these ...