Back to JavaScript Notes
Topic #280

Arithmetic Operators

You will be able to use JavaScript arithmetic operators to add, subtract, multiply, divide, find remainders, raise numbers to powers, and change numeric values by one.

What it is

Arithmetic operators are symbols that perform math on numeric values. In JavaScript, the main operators are + for addition, - for subtraction, * for multiplication, / for division, % for modulus, ** for exponentiation, and ++ or -- for increment and decrement. They work on numbers, but JavaScript may convert other values to numbers first.

A useful mental model is that each operator takes one or two operands and returns a new value. Binary operators like + need two operands. Unary operators like ++ need one operand and can change that operand's value.

Why it matters

  • Calculate totals, prices, scores, and measurements.
  • Find remainders for pagination, clock math, and even/odd checks.
  • Grow or shrink counters inside loops.
  • Compute powers for compound interest, area, volume, or scaling.
  • Convert user input into numeric results for programs.

Syntax or steps

The smallest useful pattern is to store a number, apply an operator, and store or print the result. Operators follow precedence: *, /, and % run before + and -. Use parentheses to control order.

let a = 10;
let b = 3;

let sum = a + b;
let difference = a - b;
let product = a * b;
let quotient = a / b;
let remainder = a % b;
let power = a ** b;

a++;
b += 2;

Use ++ when you need to add exactly one. Use += when you need to add a larger amount.

Example

const price = 10;
const quantity = 3;
const taxRate = 0.1;
const discount = 5;

const subtotal = price * quantity;
const tax = subtotal * taxRate;
const total = subtotal + tax - discount;
const average = subtotal / quantity;

console.log(subtotal); // 30
console.log(tax);      // 3
console.log(total);    // 28
console.log(average);  // 10

console.log(10 % 3);   // 1
console.log(2 ** 8);   // 256

let count = 5;
console.log(count++);  // 5
console.log(count);    // 6

Part by part: price * quantity multiplies unit price by number of items. subtotal * taxRate calculates tax. subtotal + tax - discount adds tax and subtracts the discount. subtotal / quantity divides the subtotal by the quantity. 10 % 3 gives the remainder after dividing 10 by 3. 2 ** 8 raises 2 to the 8th power. count++ returns the old value first, then increases count by one.

Common mistakes

  • Using + with strings: "5" + 3 becomes "53", not 8. Convert with Number("5") or use unary plus: +("5") + 3.
  • Assuming modulus is always positive: -10 % 3 is -1 in JavaScript because the sign follows the left operand.
  • Confusing x++ and ++x: x++ uses the old value, then increments; ++x increments first, then uses the new value.
  • Dividing by zero: 1 / 0 gives Infinity, and 0 / 0 gives NaN. Check inputs before dividing.

When to use it

Use arithmetic operators when you need direct numeric calculations. If you need repeated addition, multiplication, or scaling, use operators directly. If you need to change a loop counter by one, use ++. If you need to add a variable amount, use += instead of ++.

GoalUseExample
Add two numbers+5 + 3
Find remainder%10 % 3
Raise to a power**2 ** 8
Increase by one++count++
Increase by amount+=count += 5

Practice

Guided exercise: write code that calculates the area of a rectangle with width = 7 and height = 4, then increases the width by one and calculates the new area.

  1. Create variables for width and height.
  2. Use * to calculate area.
  3. Use ++ to increase width.
  4. Calculate the new area.

Expected output: 28 then 32.

Challenge: use modulus to determine whether 17 is even or odd. Hint: compare 17 % 2 to 0.

Quick check

Question: What does 10 % 3 return, and why?

Answer: It returns 1, because 3 goes into 10 three times with a remainder of 1.

Summary

Arithmetic operators let JavaScript perform basic math, calculate remainders, raise numbers to powers, and update counters. Choose the operator that matches the calculation, and remember that JavaScript can convert values and that increment operators have timing differences.

Want to go beyond the notes?

Join Coding Now Tech Institute's JavaScript course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Arithmetic Operators – FAQs

Quick answers about learning Arithmetic Operators in JavaScript.

This free note from Coding Now Tech Institute explains Arithmetic Operators in JavaScript — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every JavaScript topic on Coding Now Tech Institute, including Arithmetic Operators, is 100% free with no signup required.
With focused practice, most students grasp Arithmetic Operators in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now