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?

Golo Roden

Posted 2018-01-21T16:55:23.953

Reputation: 523

I've usually compared to a piece of paper for storing some information: You can keep writing what you know about it on a piece of paper or just change it. Different variables are like different pieces of paper/post-its. You just track stuff along. However, I've found it easier to teach this with "typed languages" than untyped ones - since it's confusing for a variable to be a string and int both in the context. But some find that easier... – PhD – 2018-03-15T19:20:40.533

A variable is a box or scratch pad. It exists during program execution. Program texts contain variable names. What does "doesn't feel correct" mean? – philipxy – 2018-11-22T22:45:35.633

21What does not feel correct about the box metapher? It's the closest to "variable = memory cell" we got. What other concepts (besides names) do Scratch variables use? – Bergi – 2018-01-21T22:50:34.630


As the placeholder text says, "Use comments to ask for more information or suggest improvements. Avoid answering questions in comments" (emphasis mine). I've moved the comments to chat because they have value, but further answers in the comment section will be removed and will not be moved to chat.

– thesecretmaster – 2018-01-22T13:01:03.537

@Bergi, you typically don't pass the box, unless you start talking about references or pointers (which I suspect is not what you want to start with). In such analogy you would open the box, and pass the content of the box as the result. – aioobe – 2018-01-24T13:11:52.160

1I can relate almost exactly to your daughter's predicament, because when I was her age my older brother was struggling to explain simple variables in algebra to me. The mutability of a variable is the thing I couldn't wrap my head around at the time. I feel like that's the key concept to communicate, but I'm still struggling with finding a way to explain it that my 9-year-old self would have understood. The accepted answer is definitely a good example, but I'm not totally convinced I would have picked it up. Hopefully your daughter is smarter than I was ;) – thanby – 2018-01-24T14:28:41.093

@aioobe Well that's exactly what's happening in a function call as well. We don't pass a variable as an argument, we pass the value that the variable holds. – Bergi – 2018-01-24T20:27:38.480

The box analogy seems confusing asf to me. I do not have a logical brain though, I am more of a creative. – ESR – 2018-01-25T03:39:21.393

@Bergi, well, then I assume the question in your original comment ("What does not feel correct about the box metapher?") is answered :-) Also, note that not all languages have pass-by-value semantics. Pass-by-reference or mixes thereof is quite common. – aioobe – 2018-01-25T06:46:09.340

@aioobe I'd say this is why the box analogy is perfect: it can express both notions – Bergi – 2018-01-25T06:53:11.743

2(I don't understand why my comment asking for more information was removed, so I'll try to rephrase it.) Why do you think you need to explain the concept of a variable? Playing around with examples might be more natural for a 9-year-old, understanding comes later. – JiK – 2018-01-25T10:44:34.767

@JiK That's how I personally learn best, perhaps that qualifies as a full answer – thanby – 2018-01-25T13:19:44.500

When I first came across algebra at age 10 the thing that confused me wasn't that X and Y could be names for abstract things; it was that I had done lots of puzzles in which X and Y represented digits in a number, so if X=2 and Y=3 then XY=23. No one explained to me that the things the letters stood for were quite different trom the things I thought they stood for, and that the notation XY wasn't decimal notation, it was multiplication. Very often in teaching, it's not getting the right idea instilled that's difficult, it's getting the wrong idea exorcised. – Michael Kay – 2018-01-26T19:00:56.400

Can you clarify why you say "'it's not easy to grasp any more" regarding the second way? That's exactly what I was thinking when I started programming (at about 11) and it felt quite easy to grasp. Even easier than the more correct box analogy. – Andrea Lazzarotto – 2018-01-28T19:25:36.673

Where I live, we have the concept of a "joker" in a deck of cards which can be treated as any card. Play some games with joker (or jack), then explain the concept through joker being a variable, able to take any value. – nurettin – 2018-01-29T11:08:33.257



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.

Ben I.

Posted 2018-01-21T16:55:23.953

Reputation: 17 660

7IMHO this is the best answer, since it explicitly addresses a way of thinking that is suited for a 9 year old child. Hence accepted :-) – Golo Roden – 2018-01-22T17:21:16.650

4Most of the other answers are technically correct but focus too much on details that are not relevant to a 9-year-old beginner programming level. The names analogy is great for when you start talking about references though. But I think that variables are conceptually different from references, so the box analogy is far less confusing. – Beefster – 2018-01-22T19:41:54.497

"Role" is fairly abstract ...I think it's the White House (or rather the Oval Office, but that's perhaps not known to a 9 year old) which contains the current president: ["And finally, be sure to include the full address of the White House to make sure your message gets to us as quickly and directly as possible:

The White House 1600 Pennsylvania Avenue NW Washington, DC 20500"](

– Peter A. Schneider – 2018-01-22T21:05:47.030

13This got protected, so I can't create an answer. I think my_age a the perfect variable that any 9 year old can immediately grasp. It's also a good lead in to classes later me.age you.age class person {int age} – gunfulker – 2018-01-22T22:02:45.623

2Terrific answer. This also transitions well to the concept of pointers. Who is the president of the senate? You could reference the role of the vice president, or you could use the name (value) of the vice president. Both are correct now, but only one will still be correct a decade from now. – Chuck – 2018-01-23T18:59:02.887

11President? Surely "teacher" is an easier concept for a child to grasp? At that age, don't they get a new one every year, juts as presidents change in your example? Or, if they have one teacher per subject, explain how the current teacher variable value changes as the subject, or classroom changes? This might all vary by country but I think that school related concepts are easier to grasp than abstract concepts like "leader" of a "country" - whatever that is when you are 9 – Mawg – 2018-01-23T19:38:03.057

1@Mawg That a 9-year-old could easily have multiple teachers muddies the waters, so to "localize" things, you could go with "Principal", of which there is only one in the entire school at any given time. When I was 9, I knew that Lyndon Johnson was President. (I was just a tad too young to know why he'd gotten the job in the first place, which happened when I was 2.) – Monty Harder – 2018-01-24T19:36:54.397

4Your last sentence, put another way: When we say that x is 40, what we really mean is that x is 40 right now. – J.R. – 2018-01-24T20:57:12.793

1There are a few comments as to a better subject to convey mutability (leaders, teachers), but if something more immediate is warranted, I think you could do well with day - if you work on the program every day, this var will be different until the end of the week, when it becomes something it was already. Day also leads to hour, minute and second, which means that you'll be writing a clock in no time. – n_b – 2018-01-25T03:06:38.470

1@gunfulker Yes! - so many confusing answers - just work through some simple examples with variables such as: currentYear, birthYear, age. Then expand it with: legalDrivingAge, yearLearnDriving, etc, etc. – Mr_Thyroid – 2018-01-26T18:03:45.307

1+1 I struggled a lot with this in particular trying to engage my 10 year old niece. This is a great way of thinking about it, and is now going to be my go-to. Using 'teacher' as the variable word works too, in the sense of "Who is your 'teacher'? My 'teacher' is __." I feel she'd grasp the concept that 'teacher' is something that can change, even though 'teacher' holds someone's name to it – psosuna – 2018-01-26T22:08:08.477

@Chuck there are some things that should be kept away from a 9-yo child and pointers might be one of them. Of course after guns, drugs, violent TV/fiction... and C++. – Andrea Lazzarotto – 2018-01-28T19:29:42.137

The first time my coding club members encountered variables is with the the player's score. It's so intuitive it barely needs explanation. Honestly I think there's a whole heap of over thinking going on here in the question and answers. – Jim W – 2018-01-29T04:10:38.507


My usual explanation is related to names; specifically names of people. People have names. The names are not the people, but can be used to refer to the people.

Some people don't have any names at all. This is common just after birth at least, before the parents decide on a name.

Names can be changed. A person can have a name for a while and then later have a different name. So, different names can refer to the same person. Similarly we have come to rely on names known to only a few other people. A father might refer to his son as junior even if their names are not the same. Spouses often call each other honey without confusion.

Just as important, a name isn't necessarily permanently bound to a thing (person, value, object). A name like Sue could refer to one person in a given household, but a different person elsewhere. Also, a name like "kiddo" could refer to one child at a given moment, but to a different child, even in the same household, at a slightly later moment.

Different names can refer to the same "object" at the same time. Different variables can reference the same thing at the same time.

A given name can refer to different objects, but not simultaneously. A variable can refer to one thing one moment but another at a different moment.

A given name can refer to a given object in one "place" but a different object in a different place.

Here "object" just means a value of some kind, not necessarily an object in an OO language. It could even refer to an operation, depending on the language.

A variable, like a name, is an association between a word (more technically a symbol) and a value. Assignments in many languages establish the association. The association is valid in a place (scope) and for a time (duration).

However, if your daughter has been studying algebra, you will need to make clear that what a mathematician calls a variable is quite different from what a computer scientist does.

In CS, a variable can actually vary, so the term is much closer to the truth. In math, especially algebra, the word variable is often used for an "as yet to be determined" but definite value (or set of values). It doesn't actually vary. Mathematicians also call them "unknowns", but that just means "not yet known until we solve this thing" but still, a definite value. In CS, variables have definite but changeable values. They are never "unknown" to the computer, but may be to the programmer who isn't actually tracing the program.

A note on "sameness".

When we say $x = 3; y = 3;$ we don't imply that there are two threes.

When we say $x = 3; ... x = 4;$ we don't imply that three has somehow become four.

In the first we simply mean that we have two distinct references (names) for 3 and in the second we mean that the (old) reference to 3 is now a reference to something else.

While every experienced programmer understands this, it can become a bottleneck for a novice. Three is three.


Posted 2018-01-21T16:55:23.953

Reputation: 21 033

6I would not introduce the concept of sameness (object identity) of persons at the same time. Every variable has its own value and can change on its own, it is not necessarily an object reference. Also I think we can (and should) introduce variables without the concept of scopes (the same name used to label different variables in different contexts). – Bergi – 2018-01-21T22:47:10.887

6With my wife, I have been using the names of animals. Obviously, my wife is not a child, but a quite intelligent woman, but her background in mathematics and statistics makes some aspects of variables in programming counter-intuitive for her, and this analogy has helped. I emphasize the name being of an animal (specifically, a turtle, since we’re practicing with a Logo-style turtle module) because animals for the most part don’t know anything about the names we assign to them. This helps emphasize that an object exists independently of names, and can have multiple names refer to it. – KRyan – 2018-01-22T02:25:20.593

5It helps her remember that the turtle we called louis, and then passed into a function, is the same turtle that function just calls turtle, and that the turtle itself doesn’t really care what you call it. – KRyan – 2018-01-22T02:28:09.293

2Not that I agree with this necessarily but I would point out another point of view. When training as a teacher we were told that it was not necessarily best to advance a child's education like this. For your daughter, she will probably be able to understand this but in future years she will have to relearn this at school and may become disinterested or disenfranchised entirely. I respect your drive to teach your daughter and I'm sure she is enjoying it but I would bare in mind that in a few years, this may not have been what was best for her. – stuart stevenson – 2018-01-22T11:09:34.343

5@stuartstevenson While I note that you said you don't necessarily agree with that philosophy, the idea of delaying the introduction of a concept usually taught at a later age horrifies me. The answer is never to restrict an interested student, but to get them different / better instruction if they've moved beyond the herd. Example: I moved from a city to a rural town in 6th grade, and hardly learned anything for 4 years because there was no option but "here's what everyone else is doing this term". Yes, I was often bored, but few would argue that my previous teachers did me a disservice. – brichins – 2018-01-22T20:49:17.807

1Names are references, not variables. Yes, in some modern languages, most or all variables contain references, but this is not the same, and it is a subtly or not-so-subtly different concept which would likely make things more difficult for the child... for example, humans usually never change their name; you have the "identity" stuff muddling stuff, etc. – AnoE – 2018-01-23T16:34:59.303

“In CS, a variable can actually vary” – I'd rather say in imperative programming, a variable can actually vary. CS per se doesn't need that. – leftaroundabout – 2018-01-23T16:54:40.550

@stuartstevenson bored and disenfranchised now, or bored and disenfranchised later? I had this problem all through my childhood, the older I got the better I was able to self motivate. My kids have it much better, each school they have been in so far has had programs that try to tailor to the kids level. Early on I honestly feared that when when they moved on to middle school/high school the same sorts of programs wouldn't exist and being forced into a more traditional classroom would be too hard to adjust to. Seems my worry was for naught. (well until college.) – Mr.Mindor – 2018-01-24T16:20:49.237

I disagree with the bit about variables in mathematics not varying - if you have: x = 2y, you can draw a graph that shows how x and y vary in conjunction with one another. – Mr_Thyroid – 2018-01-26T17:48:18.143

Actually, such a statement just defines a relationship between two values. There is nothing necessarily implied about varying in it. It is you that varies the values, meaning mostly that you decide to explore several (or all) pairs in the relationship. A variable in, say Java, is quite a different thing. – Buffy – 2018-01-26T17:56:43.963


What about

You have alot of values that you need to remember, so you put a label on each one (a little piece of paper to remind you what this value means) so you can find the value easily when you need it.


Posted 2018-01-21T16:55:23.953

Reputation: 359

1A good variation of this, is that its a box with a number or sentence in it, and each box has a label saying whats in it. Then you can use the metaphor to ask further questions. "The Box X has some oranges in it, and 2 oranges in your hand. If you know there are 10 oranges all together, how many oranges in box X ? ( X + 2 = 10 ) – Shayne – 2018-01-22T08:11:17.973

1@Shayne Scratch is an object oriented system, so there are objects (including values such as string and numbers), and there are variables which have names and refer to objects. You would have to unlearn the box metaphor once you try to put the same object into two boxes. This causes constant confusion in Java where references to objects are passed by value, so people get taught that 'primitive' variables act like boxes and 'reference' variables are different, despite the physical behaviour being identical. – Pete Kirkham – 2018-01-24T11:50:52.383

@PeteKirkham have a box labeled A with an orange in it. have two more boxes, labeled B and C, and put a note reading "A" into each. two notes, one orange. – Will Ness – 2018-01-25T11:18:28.827

1That would correspond to a different case, such as in C++ where you can have a as a pointer and b and c references to a (putting an apple in a would cause b and c to refer to the apple, not the original orange) – Pete Kirkham – 2018-01-26T08:37:57.183


The variable that children are most familiar with is score: whether in computer games, sports or board games, a child will almost certainly understand that a score is a value that is clearly not constant.

Variables are abstract, but using familiar examples turns this into something easy to grasp.

Once numeric variables are understood, you can extend the metaphor to cover string variables in a related example, e.g. the word to guess or the player's name.


Posted 2018-01-21T16:55:23.953

Reputation: 221

You beat me to this because of this question's protected status! Score is arguably the best way to teach a kid about a variable. In fact, the "score" is a variable you use every day, all the time. Watch a basketball game, and ask what the Celtic's score is repeatedly throughout the game, the score changes, but it's still the score. It's a number, it changes, people talk about "the score", it's shown on the screen, etc. Perfect example. Much less nebulous than "a box" that has a number in it. My second example would be "Mad Libs". – Gorchestopher H – 2018-01-30T18:37:44.797


Memory is a linear sequence of storage locations.

Like a lined sheet of paper.

Take a lined sheet of paper and choose a line.

In the left margin, write a label.

The variable is that label - it gives a name to a spot.

Now look for the label and write something to the right of the margin.

That is assignment.


Posted 2018-01-21T16:55:23.953

Reputation: 111


I just saw Buffy's answer so all credits to @Buffy and though I could simplify it with one word in a way that 9 year old me would have understood.

(Although bear in mind I was also mucking around with Visual Basic 6 at 9 years old so this could also be very inaccurate & harder to grasp)

A nickname.

x = "the name of the program in scratch";

x is the nickname of what you're making in scratch

A way to implement this (not sure if possible in Scratch as I've never used it): Make X the title of the application/game/program and tell her to change the program's nickname (x) and then the programs full name/first name.

It might also help to explain the possibility of errors (if any are possible), example being, rename the x variable where it's defined, but not referenced, then watch the errors pop up for unknown variable 'x' because you "changed the 'nickname' without telling anyone"


Posted 2018-01-21T16:55:23.953

Reputation: 171

Thank you everyone for your up votes, I'm still dumbfounded that I managed to get enough reputation to comment in this community from one comment overnight. Thanks again guys, hope my answer help(ed/s) :) – Brandito – 2018-01-23T05:47:39.467


It might be a bit indirect but around that age I bootstrapped myself from fill in the blank math problems through basic algebra to more generalized variable use.

eg I started with having been given problems like:

5 + __ = 9, what number goes in the blank?

From there naming the blank to get to basic algebra problem:

5 + X = 9, solve for X.

From there a programming variable just lets you use the same place holder repeatedly. (While the same is true of variables in math systems of equations, etc are probably a bit too advanced for the average 9 year old.)

Dan Neely

Posted 2018-01-21T16:55:23.953

Reputation: 161

A variable in algebra is quite unlike a variable in computing. In your fill in the blanks, only one value will be "correct". It can't vary. This will become extremely confusing later and is often a stumbling block for new programmers who know algebra already. – Buffy – 2018-01-22T19:22:07.540

1@Buffy it never was for me. ¯\(ツ)/¯ It was long enough ago that I don't recall if I was aware of graphing functions where variables did vary within a single expression, saw a programming variable changing as equivalent to x having different values in each problem in a set of questions, or something else. – Dan Neely – 2018-01-22T19:55:10.057

@Buffy I disagree that it's confusing. X can be anything in Dan's example. Only one value actually makes it true. I think that's kind of the entire point. – corsiKa – 2018-01-24T00:09:14.410

Op's kid is "heavily interested in science, robots, computers". Shouldn't they start at the beginning and learn algebra? (+1) IME learning equations that solve for X was easy. It's expressions that I don't like, because there's no solution when there's more than one variable. If they understand mathematical expressions, wouldn't they understand variables in computing? AFAIK, you definitely need to understand what X means in an equation before you even touch expressions. – Mazura – 2018-01-25T02:41:16.423


If I remember correctly, Scratch has two kinds of variables - object-bound and global. When teaching my son about Scratch, at the time of introducing variables I told him he had been working with object variables/properties the whole time: the position x and y (and to a lesser extent the object sprite/appearance (not sure what it is called in the English version of Scratch)).

From there it was easy to introduce more (custom) variables as more properties of the corresponding character - whether the monster is alive or not, how much energy it has, etc.

The general concept of variable (not bound to a specific object) can follow later: instead of "something we know about an object", talk of "something we know".


Posted 2018-01-21T16:55:23.953

Reputation: 61


If this child plays Minecraft, you can try the following analogies:

  • A variable is like a chest with a sign next to it. You can put stuff into a chest (assignment). This "stuff" in the chest is the value of the variable.
  • A function is like a workbench, which transforms inputs (like wood) into the result (like wood planks in Minecraft).

It is also helpful to explain to the child that the assignment operator (=) is better represented by an arrow (<-).

Then it becomes more logical:

var chest;

chest = "some value"; // chest <- "some value";

A completely different strategy would be to learn the assignment construct by heart. Of course, she should only learn the building blocks (e. g. the syntax and meaning of assignment to a variable) of programming by heart, NOT the solutions. You can add an Anki card with the following contents:

Question: If you execute the statement

var chest = "bla";

what will chest contain thereafter?

Answer: Text (string) "bla".

Finally, repetition is your friend. My child started to understand these concepts after we've done several algorithm lessons on FreeCodeCamp. I cannot remember how often I repeated the concept of assignment to my child (always in a different programming problem) until he started to understand it.


Posted 2018-01-21T16:55:23.953

Reputation: 407

I kind of want the metaphor to involve putting the sign on a different chest. (first the sign meant one chest, then the sign meant a different chest, the chest can vary, this is called 'variable assignment' ) – Pete Kirkham – 2018-01-24T11:33:56.730


On Steam is the game Human Resource Machine. While it is a game it is played using simple programming commands as blocks like Scratch, has an input and output conveyor and several places to hold intermediate calculations or values, think variables. Latter in the game you can even name the locations.

While some of the problems are too hard for someone 9 years old, the upside of the game is that it gives you a visual representation to the abstract concept of a variable. It also has a character that moves the boxes around and performs simple operations such as add based on the commands.

As such when I read your question what I see as the true question is how do I get a 9 year old to understand a variable as an abstract concept. The game gives helps in that it gives the player a concrete and visual representation of a variable as something concrete being interacted with the game character. Once the player understands what a variable is, they can abstract that away in the way professional programmers do with many concepts.

Also I would not consider a variable as the first abstract concept a child learns but the concept of words and numbers. The words are typically one word to one concrete item. A number is one value to a count of concrete items. A number can also be a way to give a unique name to group of similar items. A variable in one of its simplest is one word to one item that has similar properties or relationships but that can be replaced as time progresses.

When I introduce variables I state that a variable has a name but in some languages also has a type. So in teaching variables it can help to also introduce the concept of type.

Guy Coder

Posted 2018-01-21T16:55:23.953

Reputation: 655

Actually, you get in trouble with the Python and Ruby people saying a variable (name) has a type. It isn't that the type is dynamic, it is that only the value to which it then refers has a type. Any name can refer to any value, but a value has an unchangeable type. – Buffy – 2018-01-22T18:43:52.043

For future reference, the difference between static and dynamic typing. In some languages (Java...) type checking is done prior to execution (statically), usually by the compiler, but possibly by another tool. In other languages (Python...) that isn't possible in general, so typing is done at run time (dynamically). Statically typed languages are necessarily more verbose than a similar dynamically typed one as more type information usually needs to be included by the programmer. There are exceptions. Standard ML, for example, can statically type most programs without any type notations. Cool. – Buffy – 2018-01-23T14:37:36.067

Python is "dynamic" but "strongly-typed" so you can't add 4 + "fred". JavaScript is "dynamic" and "weakly-typed" so converts types in expressions and causes endless confusion. – Andy Dent – 2018-01-24T11:49:34.513


Honestly all these analogies are extremely confusing. The box analogy was the best. I would just add to it.

You have a box that has its entrance restricted like those block match toys for babies (to match shapes - for example they only take circles, or stars, etc). Some boxes only take stars (int), squares (string) etc. The box is small and only has enough space to fit one shape.

But your box has certain properties. The bottom of the box has a one of these restricted opening to allow blocks to be pushed out the other side. So because the box is small, if you try to push another star into the box when there is already a star in there, it pushes the old one out and then only the new one is inside. This handles the idea of replacing values. And then of course types are explicit. If you try to put another shape into the box it wont fit.

When you want to use the item you stored away in the box, you tell your program (assistant) to go fetch the box from the closet and bring it back to you so you can see what's inside. If you don't use the box as storage your program (assistant) is kind of forgetful (really old assistant) and may misplace the information.

So this is why you store important things you want to remember inside the boxes.

I think that covers all the bases. That is how I would explain variables.

This seems like a very straightforward analogy. There is no abstraction which means even a kid can understand it in terms of real physical things. Children tend to have issues understanding abstraction, which is why algebra is generally left for when their brains are more developed. So this real world simple comparison should be understandable.

Tyler S. Loeper

Posted 2018-01-21T16:55:23.953

Reputation: 131

The box analogy has serious problems. Suppose I have 20,000 boxes? How do I find the one I want? The answer leads you deeper and deeper into harder to understand issues. Can I put the same shape into two different boxes? Is it really the "same" shape (value) then? – Buffy – 2018-01-22T19:20:30.560

There may be a better way to explain this, but I think this will cover all the bases at her level and have her still understand it. – Tyler S. Loeper – 2018-01-22T19:59:43.580

I worry about explanations that don't smoothly extend to deeper explanations and that need to be "undone" before a student can move forward. I don't think the early explanation needs to be deep or complete, but it needs, at least, to be extensible. That is why I raise the issue of lots of boxes and several variables referring to the same value. If you explanation fails there, it just fails. Even a kid can raise those same questions and eventually a bright (or even random) one will. Never set up a situation in which you need to "unteach" anything to move forward. – Buffy – 2018-01-22T20:50:17.703

1@Buffy I don't see any problems with the box metapher. If we have multiple boxes, we label them to distinguish them - just like we do give names to variables. And if we have really many of them, we need to put some structure on it, be it scoped names or arrays (rows of boxes). Regarding "same shapes", that's where most physical analogies break down. But first we would need to define the terms "same" and "value" anyway. In fact, before introducing references/pointers/objects, we do have multiple distinct but equal values in the boxes indeed - and some magical cloning device. – Bergi – 2018-01-23T03:20:40.127


There are a number of fine answers already here. This is how I thought of doing it, and it might provide another alternative that should be suitable for a 9 year old, and possibly younger. It should be something that gives a good visual image for the child to picture mentally.

If I were speaking to the 9 year old:

Say one day you decide you're really curious about the number of blue cars that pass your house on a typical day. That makes you think about the red cars, too, and the total number of cars.

So, you get three cups - a blue one, a red one, and a clear one. Also you get a big stack of pennies. You sit on the porch all day. Every time a car goes by, you put a penny in the clear cup. If the car is blue, you also put a penny in the blue cup. If the car is red, you also put a penny in the red cup.

At the end of the day, you count the number of pennies in the blue cup. That's the number of blue cars that went by. You do the same thing with the red cup, and that's the number of red cars that went by. Finally, you count the pennies in the clear cup, and that's the total number of cars that went by.

The cups are variables, and each has a name - the blue cup is a variable named blue-cars, the red cup is named red-cars, and the clear cup is named total-cars. Each variable holds a number, the number of pennies in the cup.

Oh, and by the way, you're the program. We can empty the cups and run you again tomorrow to count the cars.

There are other things you can do, too. You can add the number of pennies from the blue cup and red cup, and see how many red and blue cars there were combined. If you want to get really fancy, you could count the number in the clear cup, then subtract the red cars and subtract the blue cars to see how many cars there were of other colors that you didn't count.

Don Branson

Posted 2018-01-21T16:55:23.953

Reputation: 161

1That's a decent visual explanation. I feel like it would be understandable to a young learner, even if they're not strong in the math department, because it's less abstract than simply trying to explain the concept of a variable. Personally I'd approach it with only the blue cup for starters, to keep it as simple as possible. Once they've got a basic understanding of that, then introduce other variables like the red or clear cups, or shift it to something other than numbers. Bonus points for the "You are the program" bit :) – thanby – 2018-01-25T13:27:59.533


A variable is just a box you put something in. And, if later you decide you want to put something different in the box, you can.

The reason I use this analogy is quite simple. As I explained to my daughter; the box doesn't change, only the contents. Further, the contents only change if and when you decide they should. I was going to expand the idea to take in constants (i.e, a box which can never be opened) but drove myself round the twist trying to figure out how the stuff got into the box in the first place!


Posted 2018-01-21T16:55:23.953


@TryHarder: love the lunchbox analogy. It got me thinking about the variable itself in a very abstract way. I don't think my daughter cares much for her lunchbox but she knows whats in it! Also, looking at the variable as a container has my head spinning. – None – 2018-03-21T20:41:59.337

2Hi Jonny! Welcome to []! Can you please elaborate on your answer, adding information about why you think a box is such an effective analogy? Maybe some examples of situations where this box analogy works well? – thesecretmaster – 2018-01-22T02:30:27.250

Your answer is simple and to the point. Good for kids. longer -> Imagine your lunchbox is a variable. Each day you go to school your friends ask "What do you have for lunch?" You open your lunchbox and look inside. "Today I have an egg sandwich." <- The lunchbox acts as a variable in that what is inside it can change......................... You could further work on this analogy to show how it might not change (kid refuses to eat egg sandwich and parents refuse to give alternative) or you could show how you can add things to a variable (add fruit the next day or sweets or something). etc etc – TryHarder – 2018-01-22T13:10:32.777

Actually, this is the memory model for C. In Python and JavaScript, what is actually stored is the location of the item in memory, which allows the variable to "find" its object and send messages to it. – ncmathsadist – 2018-01-22T17:38:45.430


The box analogy seems good to me. If you want to continue the programming "language" analogy, variables are pronouns. In English, we rely on people using context to figure out what a pronoun refers to, but in programming we explicitly tell the computer what the pronoun refers to. You could have variable names like "it", "that", "the_thing", "the_other_thing" to reinforce that.

Something else to consider is to ask her how to do something. "Play dumb", so she has to be really explicit. If you choose the task well, she will repeatedly say things like "Take the thing that you got in step 4 and ..." This will then lead to the concept of "What if we could just use some short name, instead of having to say 'the thing you got in step 4' each time?"


Posted 2018-01-21T16:55:23.953

Reputation: 191

When I learn programming as a kid on the C64, the book I used , used the 'a variable is a box with a name like X or $Y that you put things in to remember'. I understood it instantly. Its a good metaphor – Shayne – 2018-01-22T08:14:12.603

+1 I also like the use of a box as a variable stand-in. It lends it's self to further analogy. All variables (boxes) have a type (maybe colour code them). They need to be declared (added to the program), and then they can hold anything that fits that type of box. So you can put characters, words and sentences in a red 'String' box. You can put numbers in your blue 'Integer' box, and you can put either in your purple 'Variant' box. You can explain arrays with a box of boxes, collections and lists with boxes that are just grouped together, and constants with locked boxes and so on and so on. – Brent Hackers – 2018-01-22T10:08:23.887


In Python, Java, or JavaScript, I talk about the type system as an ecosystem of different species of smart data. Objects are self-aware chunks of memory to which you can send messages and which can do work for you. I will frame this discussion in JavaScript.

Example in Node

> console.log("foo".length);

As you know, it rapidly becomes tedious to do this with literals. That's when we do this.

> var x = "foo";
> x.length

The variable is like a phone number. It gives you a means by which you can communicate with its object. Assignment binds an object to a "phone number." On a deeper level, a variable knows WHERE its object is in memory and knows how to find it. Hey, that's like your phone. If you get on an airplane and fly to Des Moines, your mother can still dial the number and ring you even though you have moved. The key idea: A variable knows how to find its object. This is my initial explanation before I get into complexities such as scope.


Posted 2018-01-21T16:55:23.953

Reputation: 1 658


I find the "box" aspect is far more important than the named aspect. Maybe it's personal bias. However, we can combine the two: it's a named box. So you can say "Go look in the 'object color' box."

If you're working with pure data (no objects), it may be effective to set up a white board, and mask off a few "boxes." Each box gets a name like "number of chores done today." Concepts like "Add 1 to the number of chores done today" start to become really meaningful that way! And it just so happens that the word for these spaces on the whiteboard is "box," which is similar to the 3d boxes you might put objects in.

Even better, it puts her in an excellent position to deal with the nuanced behavior of reference mechanics when she gets there. If you're used to thinking of variables as spaces on a whiteboard, writing references to objects, like referencing the members of your family by name, is easier. For many people, the jump to reference mechanics is a real struggle because they got used to the idea of "x is my bear, that's in a box on the shelf" rather than "x is a variable referencing my bear. Y also references the same bear." (I personally have struggled to help people with reference mechanics because it forces them to unlearn whatever models they used up to that point, and unlearning is hard)

You can even use different color markers for references and data. That starts to get them used to the idea that there is some fundamental difference between the word "dad" and a reference to Golo Roden.

Cort Ammon

Posted 2018-01-21T16:55:23.953

Reputation: 661


I like to explain it as a placeholder. So that I don't have to read and write so much.

I have a friend named John Jacob Jingleheimer Schmidt. His name, John Jacob Jingleheimer Schmidt, is my name too. Whenever I go out with John Jacob Jingleheimer Schmidt, the people always shout. There goes John Jacob Jingleheimer Schmidt. John Jacob Jingleheimer Schmidt is my best friend. John Jacob Jingleheimer Schmidt likes to go down the slide at the park. John Jacob Jingleheimer Schmidt has brown hair.

Or I could just write at the top of the paper

JohnsName = John Jacob Jingleheimer Schmidt

I have a friend named JohnsName. His name, JohnsName, is my name too. Whenever I go out with JohnsName, the people always shout. There goes JohnsName. JohnsName is my best friend. JohnsName likes to go down the slide at the park. JohnsName has brown hair.

This often prompts "Can't I just say John instead?" and I tell them "Yep, we could even just say "J = John Jacob Jingleheimer Schmidt" and make it even shorter."

"Plus if John changes his name in the future we only have to change it at the top of the paper. "


Posted 2018-01-21T16:55:23.953

Reputation: 131

1I really like how this example shows abstraction in a fairly intuitive way, without having to directly define it – thanby – 2018-01-25T13:33:07.587

Yes, but as a first cut the definition of abstraction is pretty simple: A simple name for a complex thing so that the name can be used instead of the complexity. – Buffy – 2018-01-25T18:53:31.147


Do you use a dry-erase board anywhere to keep track of chores, or a shopping list?

An erasable space is a great way to teach the use of a variable.

You can even get into data types!

Booleans - eg: a tick in a box or the words yes/no against a task trash taken out. I know one mum who had a checklist at the door, so ticking off everything on the list would be essential before going to school, then the list gets erased back to all false on getting home, ready for the next day.

Integers - have a box for number of times someone has to dry dishes this week, with the tally written next to it. That gives the concept of accumulating and rewriting a value.

A calendar on which you can only write or add stickers is a WORM (Write Once Read Many) device. Without getting into the acronym, it's a good way to discuss the idea of being able to change something vs being able to get a value from it.

Andy Dent

Posted 2018-01-21T16:55:23.953

Reputation: 211


I'm not sure there's a "magic" explanation you can give her such that she will achieve "crystal clarity." I think with most people, and especially with kids, you need to demonstrate this and then "let it sink in." One of the first programs I wrote (guided by my then much older IBM 370 systems programmer brother-in-law) specifically to learn what variables are and how they are used computed Fibonacci numbers. I think we used Fortran back then. You get the idea though.... you have a 3 variables, sum, num1 and num2. You know the rest... Get your daughter to write a program that does that. Even help her write it. A lot. Just involve her in the writing and show her how it dumps out:0, 1, 1, 2, 3, 5, 8, ...

It will sink in.


Posted 2018-01-21T16:55:23.953

Reputation: 119

1Not many explanations are "magic" for any student of any age. An explanation should be more of a "conversation" than an "answer" so that the learner can reveal what they still don't get and the teacher can refine the explanation, filling in the needed bits until the A-Ha experience. This is why "The Perfect Lecture" is an oxymoron. – Buffy – 2018-01-22T21:42:15.350


I remembered an exercise for children in the Etoys-System I read about some time ago. It does that not by explaining what a variable is but by introducing the need for variables.

In the exercise children create a car in the Etoys-System (it's based on Squeak) that can drive around on the screen. They also create a steering wheel which can be used to steer the car.

This demostrates the need for variables because the facing of the wheel is connected to the facing of the car. It connects two properties of the micro-world without specifying what the value of the properties is.

You can find the paper with the exercise at says it is a good way to teach about variables. The exercise is on page 2.

Viktor Seifert

Posted 2018-01-21T16:55:23.953

Reputation: 111


I would use integer math. On a sheet of paper, set up a small arithmetic table with three columns marked X, Y and 10. Include a '+' between X & Y and an '=' between Y & 10. Fill in 10 down the rows, and start by plugging figures into the X & Y. So, row 1 will have 1 for X and 9 for Y, row 2 will have 2 for X and 8 for Y etc.

Have your daughter fill in the information for the rest of the rows and then point out that X and Y are the variables - because their values can vary - and can have a range of answers that are all correct.

This will not only point out the variable concept, but also help out when they throw algebra at her at school in a few years.


Posted 2018-01-21T16:55:23.953

Reputation: 111


This answer is probably a little more advanced than you're looking for, but it might help somebody else in the future, especially if they're working in a Java-like language.

I really like this description: Cup Size -- a story about variables.

This describes variables as cups. You have different sized cups, which means they can hold different types of things. Each cup has a name written on it, so you can say "give me the thing in the large cup with a name of X".

It then talks about the more advanced idea of references, which it describes as remote controls. A remote control goes in a cup, and points to a TV.

It also has a follow-up article: Pass-by-Value Please, which describes the fact that one TV can have multiple remote controls, each in a cup, and swapping out one of the remote controls for one that points to a different TV doesn't change the original TV. Like I said this is more advanced than you care about, but it really helped me understand the idea of pass-by-reference vs pass-by-value back when I was still figuring that stuff out.

Kevin Workman

Posted 2018-01-21T16:55:23.953

Reputation: 4 605


Has she done basic algebra? "A white box has three marbles in it, and a blue box has four marbles in it. If I have six white boxes and five blue boxes, how many marbles have I got?" Is her maths up to this level yet? At age 9, I'd hope so.

You can also make life easier by calling the variables something meaningful, which is good programming practise anyway. So your variables would be "number_of_marbles_in_a_white_box", "number_of_marbles_in_a_blue_box", "number_of_white_boxes", "number_of_blue_boxes", and "number_of_marbles". Restrain your natural tendency to use shorter names.


Posted 2018-01-21T16:55:23.953

Reputation: 296


The issue is that a variable is not just one thing -- it can do a variety of things -- and also, that variables do not exist in nature. Nothing else in a person's experience behaves in all of the ways that a variable can. So, you need a ramp that begins simply and describes the various variations of variables.

Early computers did not have any programming, they were circuits connected by cables. If you wanted a push-button to affect the computer, you used a wire to connect the push-button to a circuit. When Binary Coding came along, you could get the input from the button by reading a value from a numbered memory address. Assembly language allowed you to give that address a name. You could call it ButtonValue or something, and just test it with an IF statement. But you could also define another variable, like Input1, and put the value in there, along with some other input values and then feed that to some code you wrote. Now we have the idea of named locations, and assignment. Good, but not nearly far enough.

A collection of similar variables can be put together in an Array, and then a variable used to index through the array. Any child should understand that, because they have all stood in line and called out numbers one by one. Finally, there is the idea of indirection, that a variable can decide which variable to refer to. I could have a variable called Greeting, and based on the current time, put one of three other variables in it, holding values like: "Good morning", "Good afternoon" and "Good Evening". Add a variable for the student's name and this program will be able to greet anyone at any time. We used variables so that the strings (Good Morning, etc) can be easily changed, possibly at the direction of a variable called Language...

Nothing else in the world works that way, but with these simple examples, it should be clear to any nine year old. The problem then will be keeping them off the computer. I spent a lot of hours writing programs to output geometric figures in text on a PDP-11 terminal.


Posted 2018-01-21T16:55:23.953

Reputation: 1

2Welcome to []! Your answer seems to be tying together many concepts, which are just slightly related to variables. It wouldn't make it simpler for a 9 year old. – ItamarG3 – 2018-01-22T16:10:39.760


First explain the kid meaning of variable as something that keeps changing (like weather). Then he will get idea about the word and then tell him, in CS how we assign a value to the variable and how we are able to change it afterwords

Chinmay Shendye

Posted 2018-01-21T16:55:23.953

Reputation: 1

3Can you elaborate on how you'd explain it? I'm not sure what you mean by "as something that keeps changing" – thesecretmaster – 2018-01-22T12:57:26.103


For a nine year old, you can say that a variable is a "change item", such as weather in the environment. On the other hand, if it proves too challenging to explain it, you can kindly postpone this subject until she is old enough to appreciate it. Bear in mind that kids at this age are not very good in abstract thinking. Try again when she is about 12-13.


Posted 2018-01-21T16:55:23.953

Reputation: 7

2No kids are fin at abstract reasoning, and theres evidence in the literature that confirms that (Think about it: Kids learn to speak ex-nihilo other than some rudimentary wetware to jumpstart grammar learning). The trick is to just not use jargon to explain jargon. "A box to put a number or sentence in" works fine. – Shayne – 2018-01-22T08:16:53.690


There is plenty of evidence to suggest that kids are not good at abstract reasoning. "Developmental psychologist Jean Piaget argued that children develop abstract reasoning skills as part of their last stage of development, known as the formal operational stage." This seems related and excerpt taken from

– TryHarder – 2018-01-22T13:21:09.870