CodeBlanks Logo Icon CodeBlanks

Arithmetic operators

JavaScript course · Beginner · Lesson 7/133

Learn basic arithmetic with +, -, *, /, % and ** operators.

Arithmetic operators

In JavaScript, the basic four operations use arithmetic operators: + for addition, - for subtraction, * for multiplication, / for division. These signs keep the meaning they have in everyday math.

For example, to compute a cafe's daily revenue you would write const revenue = price * cups;. The operator takes two values, produces a new one and assigns it to the variable.

Modulo and exponentiation

Two more operators will come in handy. % (modulo) gives the remainder of a division: 17 % 5 returns 2 because 17 = 3*5 + 2. It is great for even/odd checks or minute-to-second conversions.

** raises to a power: 2 ** 3 returns 8. The same as multiplying three 2's together. Use it for areas or compound interest.

Exercise Compute the total price

Declare a total variable and assign the product of price and quantity. Use the multiplication operator.

Show example solution
const price = 25;
const quantity = 4;
// Total price
let total = price * quantity;

Test yourself

  1. What is the result of 6 * 7?

    console.log(6 * 7);
    • 36
    • 42
    • 13
    • 67
    Show answer

    42 — Correct. 6 times 7 is 42.

  2. Write the remainder operator

    const remainder = 17 ____ 5;
    console.log(remainder);
    Show answer
    const remainder = 17 % 5;
    console.log(remainder);
  3. Match each operator to its meaning

    +
    Addition
    -
    Subtraction
    *
    Multiplication
    /
    Division

All lessons in Beginner