Skip to content

Variables: Storing Information

Beginning of the lesson

Variables: Storing Information

A named box where a program keeps a piece of information

Big Idea: A variable is like a labelled box. It has a name so the program can find it, and it holds a value the program can use and change later.
By the end you will be able to:
  • say what a variable is in simple words,
  • name the two parts of a variable: its name and its value,
  • explain how a program updates the value inside a variable.

1. What is a variable?

A variable is a place where a program stores one piece of information so it can use it later. Think of a small box with a sticky label on the front. You write a name on the label, and you put something inside the box.

Later, when the program needs that information, it does not have to remember every detail. It just looks for the box with the right label and reads what is inside. That is why variables are so useful: they let a program keep and find information.

The word variable means "can change". The value inside the box does not have to stay the same forever. The program can open the box, take out the old value, and put a new one in.

2. The two parts: name and value

Every variable has exactly two parts. Once you know these two parts, you understand variables:

PartWhat it isExample
Namethe label on the box, so the program can find itscore
Valuethe information stored inside the box right now10

So a variable named score holding the value 10 is just a box labelled "score" with the number 10 inside. A good name describes what is in the box, like score, age, or playerName. That makes the program easy to read.

A value can be a number (like 10), a word or piece of text (like Sam), or other kinds of information. The box does not care what you put in it, as long as it holds one value at a time.

Continue this lesson on YourAIZone

The full lesson has the complete explanation, worked examples, common mistakes, tests with instant checking and an AI tutor. Start right away as a guest, or create an account to keep your progress.

In the full lesson

  • The complete explanation
  • Worked examples
  • Common mistakes and how to avoid them
  • Test questions: 15
  • AI tutor that answers questions about the topic
  • Progress tracking for students, parents and teachers