Variables: a named box for a value

Knowledge Videos

Short animated explainers, organised by subject.

Variables: a named box for a value

A variable holds a value under a name, and the value can change. Score, set and change, and what score = score + 1 means.

Transcript

A variable is a named box that holds a value. This box is named score, and right now it holds zero.

The value can change. Change score by one, and the box holds one. Again, and it holds two. That is why it is called a variable: it can vary.

Programmers write this as score equals score plus one. Read it as: take the old value, add one, and store the new value back in the box.

A variable can hold a number, or text, like a player name. Its name tells you what is inside.

Remember: a variable is a named box that holds a value, and the value can change.

More in this series