What are variables?
A variable is a simple way of storing one piece of information somewhere in the computer’s memory whilst a program is running, and of getting that information back later. A variable is an example of a data structure. As pupils move on to Secondary school, they will learn about other data structures such as arrays. A variable can be numerical, textual or perhaps an indicator of true/false. Programs can store, retrieve or change the values of variables. Variables are an abstraction of data storage and retrieval: as programmers, we need not know how exactly the programming language, operating system and hardware manage and handle them.

Examples of variables: username, password, each detail of an online order, and scores and lives in a game.
One popular way to think about a variable is to imagine that it’s like a box that can hold values. The box is labelled; this is the name of the variable. The variable can only store one thing at a time. If we retrieve the value from a variable, we look to see what that value is but do not remove it: nothing has been taken out of the box. We can update what is stored in the variable at any time as the program is running – for example, increasing the value of a score variable in a game.

A variable can be thought of as a box that can hold one value at a time.
The process of creating variables is sometimes called declaring. In Scratch, to create a new variable, you simply give the variable a name and decide if it will exist for all sprites or just one sprite. We need to remember to set a value for each variable at the start of our program; this is called initialising. If we do not remember to do this, and then re-run the code (in the same session), the variable retains the value that it had when the program was last run. This could mean we find ourselves playing a game starting with the previous player’s score!

Examples of creating variables: in Scratch, in Python and in MSW Logo.
Why are variables important?
Variables and other data structures are how computers store and manipulate information. Variables capture entered data; they enable values to be displayed and fed through to other systems; they hold intermediate values in calculations. We teach pupils to work out which variables are present in systems and programs, drawing on the same range of computational-thinking principles used by ‘real world’ developers. The use of meaningful, unambiguous names for variables facilitates the reading of code, especially important in large-scale programming projects where multiple teams may work on code over months, if not years; poorly named variables obscure the purpose of code and can make debugging almost impossible. Certain staff may even have the specific role of maintaining consistency and coherence in the names of variables and other data structures, often using standardised naming formats.