Back to course

Arithmetic Operators: Addition, Subtraction, Multiplication, and Division

JavaScript: The Complete '0 to Hero' Beginner Course

26. Arithmetic Operators

Arithmetic operators perform mathematical calculations.

OperatorDescriptionExample
+Addition5 + 3 (8)
-Subtraction5 - 3 (2)
*Multiplication5 * 3 (15)
/Division5 / 3 (1.666...)
%Modulus (Remainder)5 % 3 (2)
**Exponentiation (Power)5 ** 2 (25)

The Modulus Operator (%)

This is useful for determining if a number is even or odd, or for cycling through lists.

javascript let x = 10; console.log(x % 2); // Output: 0 (10 is even)

let y = 11; console.log(y % 2); // Output: 1 (11 is odd)

Order of Operations (Precedence)

JS follows standard mathematical rules (PEMDAS/BODMAS):

  1. Parentheses ()
  2. Exponents **
  3. Multiplication *, Division /, Modulus % (left-to-right)
  4. Addition +, Subtraction - (left-to-right)

javascript let result = 10 + 2 * 5; // 10 + 10 = 20 let trickyResult = (10 + 2) * 5; // 12 * 5 = 60