1.10 — Operators roundup
One skill left before your first project: combining small questions into big ones. “Is the user an adult AND holding a ticket?” “Is this field empty OR over the limit?” Real conditions are built from pieces — glued together with the logic operators &&, || and !.
And there’s a secret about how the machine reads them: not left-to-right like you read text, but as a tree, evaluated from the leaves up. See the tree once, and operator precedence stops being a memorized table and becomes a picture.
let age = 20; let hasTicket = true; console.log(age >= 18 && hasTicket); console.log(!(age > 25) || age === 20); console.log(2 + 3 * 4);
The cast. Comparisons (>, >=, ===, !==…) each produce a boolean — they’re the boolean factories from lesson 1.7.
The deeper story, with the real names for things — this part is what turns “I saw it” into “I can explain it.”
You now own operators from four families — here they are in one place. Arithmetic does math: + − * / %, and ** for powers. Comparison asks a question and answers true or false: > < >= <=, plus the strict pair === !== from 1.9. Logical combines those answers: && (AND), || (OR), ! (NOT). Assignment stores results: =, with the shortcuts += −= *= /= from 1.3.
When several operators share one line, the engine applies them in a fixed order: ! runs first. Then arithmetic (* before +, as you watched). Then comparisons. Then &&, then || — and = always last. But here is the honest professional habit: nobody remembers this full list. When in doubt, add parentheses — they redraw the tree exactly how you want.
A preview, not homework: && and || actually hand back one of their two SIDES — not always a fresh true or false. So "hello" || "fallback" gives "hello", the actual string. Programmers use that as a default-picker. The full trick clicks in lesson 2.2, after truthy and falsy.
The skip you watched (short-circuiting) is more than a speed trick — real code depends on it. An example built only from tools you own: count !== 0 && total / count > 5. When count is 0, && skips the right side entirely — so the division by zero never happens. The left side protects the right side.
💼 On the job — a test assertion IS a boolean expression. Every “did it pass?” your future suites answer is one of these trees evaluating to true or false. “Status is 200 AND the reply includes the id AND it took under 2 seconds” — that is three comparisons and two &&s. Today’s grammar is the daily language of test automation. You now have the full grammar of Phase 1 — time for the checkpoint.
✏️ Quick check 1
Type what 10 > 5 && 3 > 7 evaluates to:
✏️ Quick check 2
A tree you have not climbed yet — type what 5 + 2 * 3 gives:
✏️ Quick check 3
true || someScaryExpression — no matter how scary the right side is, the whole thing always evaluates to? Type it.
🗣️ Now teach it back
Explain to a friend: how does the machine evaluate age >= 18 && hasTicket (use the tree picture), and why is 2 + 3 * 4 equal to 14 without any memorized rules?
Write it as if your friend is sitting next to you. Saved to your journal — future-you will use these notes to teach others.