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 moreArithmetic 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 ZeroThe Number ZeroCounting to FiveCounting to 10Counting to 20Counting a Set of Objects Up to 20Cardinality: The Last Number CountedMatching Numerals to QuantitiesSubitizing Small QuantitiesAddition Within 10Making 10 as an Addition StrategyAddition Within 20Doubles and Near DoublesDoubles Facts Within 10Near Doubles Facts Within 20Mental Math Strategies for AdditionMental Math: Adding and Subtracting TensAddition Within 100Repeated Addition as MultiplicationMultiplication as Equal GroupsMultiplication: ArraysBasic Multiplication Facts Through 10Multiplication Facts Within 100Division as Equal SharingDivision as Grouping (Measurement Division)Division: Grouping (Repeated Subtraction) ModelDivision: Fair Sharing ModelDivision as Equal SharingDivision as GroupingBasic Division FactsDivision Facts Within 100Multiplication and Division Fact FamiliesRelationship Between Multiplication and DivisionDivision Facts as Inverse of MultiplicationRemainders and Quotients in DivisionDivision Word ProblemsMulti-Step Word ProblemsSolving Multi-Step Word ProblemsMultiplication Word ProblemsDivision Word ProblemsIntroduction to Long DivisionFactors and MultiplesPrime and Composite NumbersEquivalent FractionsRelating Fractions and DecimalsDecimal Place ValueIntegers and the Number LineOpposites and Additive InversesAbsolute ValueAdding IntegersSubtracting IntegersMultiplying IntegersIntroduction to ExponentsOrder of OperationsOperators and Expressions

Longest path: 55 steps · 264 total prerequisite topics

Prerequisites (3)

Leads To (3)