AlgoViz
← Back to trail

What is a Variable?

Easy+15 XP

The smallest idea in all of code: a labeled box that holds one value — and that value can change.

No visualization loaded.

Watch

i

Press Run to begin.

A variable is a single labeled box that holds one value. You give the box a name (like 'score'), put a value inside, and later you can change that value — but the name stays the same. Think of it as a sticky-note label on a jar: the label says 'score', and what's in the jar can change all day long.

What's the difference between the variable's name and its value?

The name is the label on the box — it never changes once you pick it. The value is what's currently inside, and it can change as often as you like. When code says 'score', it means 'whatever is in the box labeled score right now.'

What does it mean to 'change' or 'assign' a variable?

Assigning means putting a value into the box, written like score = 10. It always goes right-to-left: figure out the value on the right, then drop it into the box on the left. A later score = score + 5 means 'take what's in the box, add 5, and put the result back in the same box.'

The box looks just like one cell of an array — is a variable the same as an array?

Almost — and that's the key link! A variable is ONE box. An array is a ROW of boxes under a single name, where you pick a box by its index. So an array is really just many variables bundled together and numbered. That's why they look alike on screen: master the single box here, and the row in the next lesson makes sense.

Can a variable hold things other than numbers?

Yes — a variable can hold a number, a word, true/false, or even a whole array. Same idea every time: a named box holding one current value. We use numbers here because they're the easiest to watch change.

🧠A variable = one named box holding one value. The name stays; the value can change. Everything else in code is built on this.
the box's value right nowits final value