There are eight arithmetic or numeric operators in JavaScript:
- Addition: a + b
- Subtraction: a - b
- Division: a / b
- Multiplication: a * b
- Remainder: a % b
- Exponentiation: a ** b
- Unary plus: +a
- Unary minus: -a
Arithmetic and numeric operators will typically coerce their operands to numbers. The only exception is the + addition operator, which will, if passed a non-numerical operand, assume the function of string concatenation instead of addition.
There is one guaranteed outcome of all of these operations that is worth knowing about beforehand. An input of NaN guarantees an output of NaN:
1 + NaN; // => NaN
1 / NaN; // => NaN
1 * NaN; // => NaN
-NaN; // => NaN
+NaN; // => NaN
// etc.
Beyond that basic assumption, each of these operators behaves in a slightly different way, so it's worth going over each of them individually.
...