Variables: Storing Information
A named box where a program keeps a piece of information
- 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:
| Part | What it is | Example |
|---|---|---|
| Name | the label on the box, so the program can find it | score |
| Value | the information stored inside the box right now | 10 |
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.