Skip to content

Programming Basics

Operators (Arithmetic & Comparison)

The idea, in plain English

Operators are the little symbols that DO something with your values, like the +, -, x, and / buttons on a calculator. 'Arithmetic' operators do math: add, subtract, multiply, divide. 'Comparison' operators work like a balance scale. They weigh two values against each other and answer with a yes/no, called a 'boolean'. Is this side bigger, smaller, or exactly equal?

How it works

  1. 1Arithmetic operators are `+` (add), `-` (subtract), `*` (multiply), and division. Division comes in two flavors: regular division, and 'whole number' division that throws away any leftover. The leftover itself is called the 'remainder', found with `%`.
  2. 2Comparison operators are `==`/`===` (is equal), `>` (greater than), `<` (less than), and `<=`/`>=` (less/greater than OR equal). Every one of these hands back a boolean, `true` or `false`.
  3. 3You can mix operators together, like checking `a > b`. The computer works out the math or comparison the same way you would with pen and paper, left to right.

When you'd use it

Use these operators anytime you do math on numbers, or anytime your code needs to decide 'is this bigger?' or 'is this the same?'. Examples: splitting a bill evenly, checking if someone's old enough, or scoring a quiz.

Common beginner mistakes

  • Using a single `=` (which SETS a value) when you meant `==` or `===` (which CHECKS if two values are equal). This is a very common beginner slip.
  • Forgetting that regular division can leave a fraction. If you only want whole numbers, you need a specific 'whole number division' tool, not just `/`.

Try it — edit and run

Click the code to edit · press ⌘/Ctrl+↵ to run

Editable code. Tab and Shift+Tab indent. Press Escape, then Tab, to move focus out of the editor.

Expected output — hit Run to try it
Add: 22
Subtract: 12
Multiply: 85
Divide (whole): 3
Remainder: 2
Is equal: no
Is greater: yes
Is less or equal: no

Not sure this is the right topic? See the learning paths → or where this leads →