A topic in the Open Knowledge Graph — a free, open map of 15,290 topics and the order to learn them in.

Operators and Expressions

College Depth 54 in the knowledge graph ☐ I know this ☆ Set as goal
975topics build on this
264prerequisites beneath it
See this on the map →
Primitive Data TypesVariables and Assignment+1 more→→Arithmetic Operators and Operator PrecedenceString Operations and Methods+1 more
operators arithmetic comparison expressions precedence

Core Idea

Operators combine values and variables into expressions that evaluate to a result. Arithmetic operators (+, -, *, /, %) perform math; comparison operators (==, !=, <, >) produce booleans; logical operators (and, or, not) combine boolean expressions. Operator precedence rules determine the order of evaluation when multiple operators appear together. Every expression has a type determined by its operands and operator.

How It's Best Learned

Evaluate expressions by hand first, then verify in a REPL. Pay particular attention to integer vs. float division and short-circuit evaluation in logical expressions.

Common Misconceptions

Explainer

You have learned to store values in variables and to distinguish between data types like integers, floats, and strings. Operators are the symbols that let you do things with those values — combine them, compare them, and build up complex calculations from simple parts. An expression is any combination of values, variables, and operators that the computer can evaluate to produce a single result. The expression `3 + 4` evaluates to `7`. The expression `age >= 18` evaluates to `true` or `false`. Even a lone variable like `x` is an expression — it evaluates to whatever value `x` currently holds.

Arithmetic operators work the way you expect from math: `+` adds, `-` subtracts, `*` multiplies, `/` divides. The one to watch carefully is division. In many languages, dividing two integers performs integer division, which truncates the result: `7 / 2` gives `3`, not `3.5`. If you want the decimal result, at least one operand must be a float: `7.0 / 2` gives `3.5`. The modulo operator `%` returns the remainder after division: `7 % 2` gives `1`, because 7 divided by 2 is 3 with a remainder of 1. Modulo is surprisingly useful — it is the standard way to check whether a number is even (`n % 2 == 0`), to cycle through a fixed range, or to wrap around indices.

Comparison operators produce boolean values. `==` checks equality, `!=` checks inequality, and `<`, `>`, `<=`, `>=` compare magnitude. The critical beginner trap is confusing `=` (assignment, which stores a value) with `==` (comparison, which tests equality). Writing `if (x = 5)` assigns 5 to `x` instead of checking whether `x` equals 5 — a bug that can be very difficult to spot because the program may still run without an error.

Logical operators — `and`, `or`, `not` (or `&&`, `||`, `!` in C-style languages) — combine boolean expressions. `and` is true only when both sides are true; `or` is true when at least one side is true; `not` inverts true to false and vice versa. A critical behavior is short-circuit evaluation: in `A and B`, if `A` is false, the computer skips evaluating `B` entirely because the result must be false regardless. Similarly, in `A or B`, if `A` is true, `B` is never evaluated. This is not just an optimization — it lets you write safe conditions like `if (x != 0 and 10 / x > 2)`, where the division only happens if `x` is nonzero. When multiple operators appear in one expression, precedence rules (which you know from order of operations in math) determine what gets evaluated first. Multiplication before addition, comparison before logic, and when in doubt, parentheses make the order explicit and the code readable.

Practice Questions 5 questions

Prerequisite Chain

Understanding Zero → The Number Zero → Counting to Five → Counting to 10 → Counting to 20 → Counting a Set of Objects Up to 20 → Cardinality: The Last Number Counted → Matching Numerals to Quantities → Subitizing Small Quantities → Addition Within 10 → Making 10 as an Addition Strategy → Addition Within 20 → Doubles and Near Doubles → Doubles Facts Within 10 → Near Doubles Facts Within 20 → Mental Math Strategies for Addition → Mental Math: Adding and Subtracting Tens → Addition Within 100 → Repeated Addition as Multiplication → Multiplication as Equal Groups → Multiplication: Arrays → Basic Multiplication Facts Through 10 → Multiplication Facts Within 100 → Division as Equal Sharing → Division as Grouping (Measurement Division) → Division: Grouping (Repeated Subtraction) Model → Division: Fair Sharing Model → Division as Equal Sharing → Division as Grouping → Basic Division Facts → Division Facts Within 100 → Multiplication and Division Fact Families → Relationship Between Multiplication and Division → Division Facts as Inverse of Multiplication → Remainders and Quotients in Division → Division Word Problems → Multi-Step Word Problems → Solving Multi-Step Word Problems → Multiplication Word Problems → Division Word Problems → Introduction to Long Division → Factors and Multiples → Prime and Composite Numbers → Equivalent Fractions → Relating Fractions and Decimals → Decimal Place Value → Integers and the Number Line → Opposites and Additive Inverses → Absolute Value → Adding Integers → Subtracting Integers → Multiplying Integers → Introduction to Exponents → Order of Operations → Operators and Expressions

Longest path: 55 steps · 264 total prerequisite topics

Prerequisites (3)

Leads To (3)