Variables, Data Types & Operators

💻 Computer Science Years 6–10 Foundation

How programs remember values in named variables, the main data types, and the operators that work on them.

Open this lesson, with practice and a printable worksheet →

Every program you have ever used — a game, a calculator, a messaging app — is really just moving values around and doing sums with them. A variable is the program's way of remembering a value and giving it a name, so it can fetch it back later. Master variables and you have the vocabulary that the rest of programming is built from.

Why this matters: You cannot write a single useful program without storing data. Scores, passwords, prices, the number of lives you have left — all of it lives inside variables. Choosing the right data type and the right operator is the difference between code that works and code that crashes.
score 7 the name is the label; 7 is the value
A variable is a named box holding one value at a time.

Variables: named boxes

score = score + 17 + 11. work out right sidescore82. store back in box
Assignment works out the right side first, then drops the answer in the box.

Think of a variable as a labelled box in a warehouse. The name is written on the outside; the value is what sits inside. You put a value in using assignment, written with an equals sign that means "becomes":

score = 7
name  = "Ava"
score = score + 1

That last line trips people up. It does not mean "score equals score plus one" as a fact — it means "work out the right-hand side, then drop the answer back in the box". So score goes from 7 to 8.

Data types: what kind of value?

IntegerRealBooleanString423.14True"hi"wholedecimalyes / notext
Each data type is a different bin: a value goes in the one that fits it.

Every value has a type, and the type decides what you can do with it. You can add two numbers, but adding two names makes no sense.

TypeHoldsExample
IntegerWhole number42
Real (float)Number with a decimal3.14
StringText in quotes"hello"
BooleanTrue or False onlyTrue
CharacterA single symbol'q'

Operators: doing things with values

17 ÷ 5DIV = whole part3MOD = remainder2
DIV keeps the whole part of a division; MOD keeps the remainder.

Arithmetic operators do maths: + - * /. Two special ones matter for exams: DIV gives the whole-number part of a division, and MOD gives the remainder. So 17 DIV 5 is 3 and 17 MOD 5 is 2.

Comparison operators ask a yes/no question and give back a Boolean: == (equal), != (not equal), <, >, <=, >=.

10 > 8compareyes / no?True
A comparison always answers with a Boolean: True or False.
Worked trace.
a = 5 → box a holds 5
b = 2 → box b holds 2
total = a * b → 5 × 2 = 10, so total holds 10
rem = 5 MOD 2 → 5 ÷ 2 leaves remainder 1, so rem holds 1
check = total > 8 → 10 > 8 is true, so check holds True
Common mistake: confusing = (assignment, "put this value in the box") with == (comparison, "are these equal?"). Writing if score = 10 when you mean if score == 10 is one of the most common beginner errors.

Give your variables honest names. numberOfLives tells the reader — and future you — exactly what the box holds; x tells them nothing.

Get the printable worksheet →
← Trace Tables & Efficiency → Selection (IF statements)
← Sasta Basta home All subjects