How to explain the concept of a variable to a 9-year old? My 9 year old daughter is heavily interested in science, robots, computers, … She asked me if I could teach her how to program a computer. So, we started with Scratch, a programming language specifically designed for kids.

She likes it a lot, and she enjoys getting visual results fast. Now we came to the point that you need a variable, and I have realized that she has not yet understood what a variable is. Of course, at school, they didn't have the concept of variables in mathematics yet (mind you, she is 9 years old).

I remember that when I learned to program, I was 12 years old, and I had a hard time grasping that, too. Although I'm a professional software developer, and I help other people a lot to learn to program, I find it very difficult to explain it to her in a sense, that she can understand, and that is suitable.

Of course I can say:


  It's like a box, where you put the number 9 into it. If I ask you how old you are, then you don't say "9", but you give me the box, and I am going to look it up on my own.


That's an analogy, and she understands it, but it's difficult for her to transfer this idea to Scratch code. It doesn't feel correct.

If I say


  It's just a name for a value, and everywhere where you normally would use the value itself, you can now use the name. This has the big benefit that you can change the value, but keep the name.


it feels correct, but it's not easy to grasp any more. To cut a long story short: In contrast to a loop (do this and that for a given number of times) or a decision (if X then Y), variables are way more abstract.

So, how would you explain the concept of a variable to a 9 year old, in a way, that it is easy to grasp AND correct at the same time, i.e. it has a direct relation to writing code?
Buffy's lovely answer shows well how two variables can refer to the same thing, but since we are in early cognitive development and working with Scratch, in which you can't pass parameters, and can't arrange for two different names to refer to the same instance/spawn, I wouldn't focus my efforts on that point yet.  What matters is the idea of a holding place and mutability.

These concepts are hard to describe in a way that a 9-year-old would already know how to mentally model, but one very similar idea with which they are already familiar is the idea of a "role".

The President of the United States is currently Donald Trump.  (You should substitute the head executive leader of whatever country your child lives in for this example.)  But a few years ago, it was Barack Obama.  Later, it could be Mike Pence, or someone else entirely.  When important things need to go to the president, they go to whoever is the president right now.  They don't go to Barack Obama any more, and some day, they will no longer go to Donald Trump.  But they always go to the President.

So, to put this into Scratch, we can make a String in scratch called President, and then we can use the set box to set President to "Donald Trump".  We can then make an item in the main field that behaves as a button, that changes that variable to [insert your child's name here].

Now, we can create another value, called x, and set that to a zero.  Now, when you press the button, change x by 4, and we can watch the variables change.  Press the button 10 times, and the value becomes 40.

So, what can we say about x?  Sometimes we say that x is 40, but is it really?  Or does it just hold 40?

This is the most important early understanding to arrive at when describing a variable.  When we say that x is 40, what we really mean is that x holds 40.