Skip to content
Home: Success TutoringTeachers

Computer Science glossary · Grade 5 to Grade 9

Variable

What it means

In coding, a variable is a named place where a program stores a piece of data, such as a score or a name. The value inside it can change while the program runs.

Examples

  • score starts at 0 and goes up by 1 each time the player catches a star.
  • name stores whatever the user types, then the program says "Hello, " and the name.
  • lives starts at 3; if lives = 0, the game ends.

For teachers

A variable has a name and holds a value that can be read, compared and updated, which is how programs keep track of things like scores, lives, timers and user answers. A common model is a labeled box that holds one value at a time; assigning a new value replaces the old one. Students should practice giving variables a starting value (for example, setting the score to 0 at the start) and tracing how values change inside loops.

Common misconception

Students often think a variable keeps a list of every value it has held. A simple variable holds only its current value; when a new value is stored, the old one is replaced.

Browse the full glossary