Operators are the symbols that do work on values — adding numbers, comparing them, combining true/false conditions. This lesson covers the five kinds you'll use constantly.
Used for math.
| Operator | Meaning | Example |
|---|---|---|
| + | Addition | 5 + 2 → 7 |
| - | Subtraction | 5 - 2 → 3 |
| * | Multiplication | 5 * 2 → 10 |
| / | Division | 5 / 2 → 2.5 |
| % | Remainder (modulo) | 5 % 2 → 1 |
Used to give a variable a value, often combined with a calculation.
let score = 10;
score += 5; // same as: score = score + 5
console.log(score); // 15<?php
$score = 10;
$score += 5; // same as: $score = $score + 5
echo $score; // 15score = 10
score += 5 # same as: score = score + 5
print(score) # 15Compare two values and produce true or false.
| Operator | Meaning |
|---|---|
| === | Equal to (checks type too) |
| !== | Not equal to |
| > | Greater than |
| < | Less than |
| >= | Greater than or equal to |
console.log(5 === 5); // true
console.log(5 === "5"); // false — different types
console.log(7 > 3); // true<?php
var_dump(5 === 5); // true
var_dump(5 === "5"); // false — different types
var_dump(7 > 3); // trueprint(5 == 5) # True
print(5 == "5") # False — different types, Python never coerces here
print(7 > 3) # TrueCombine or invert true/false values.
| Operator | Meaning | Example |
|---|---|---|
| && | AND — both must be true | true && false → false |
| || | OR — at least one true | true || false → true |
| ! | NOT — flips the value | !true → false |
Work directly on the binary representation of numbers, bit by bit. You will use these far less often than the operators above, but they show up in low-level code, graphics, and permission flags.
console.log(5 & 1); // 1 — AND on the underlying bits
console.log(5 | 2); // 7 — OR on the underlying bits<?php
echo 5 & 1; // 1 — AND on the underlying bits
echo 5 | 2; // 7 — OR on the underlying bitsprint(5 & 1) # 1 — AND on the underlying bits
print(5 | 2) # 7 — OR on the underlying bitsBitwise operators make a lot more sense after the Binary Numbers lesson — it's fine to skim this section for now and come back to it.