# 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?

• What 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 Jan 21 '18 at 22:50
• 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 Jan 22 '18 at 13:01
• @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 Jan 24 '18 at 13:11
• I 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 Jan 24 '18 at 14:28
• (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 Jan 25 '18 at 10:44

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.

• IMHO 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 Jan 22 '18 at 17:21
• Most 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 Jan 22 '18 at 19:41
• This 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 Jan 22 '18 at 22:02
• President? 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 says reinstate Monica Jan 23 '18 at 19:38
• Your 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. Jan 24 '18 at 20:57

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.

• I 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 Jan 21 '18 at 22:47
• With 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 Jan 22 '18 at 2:25
• It 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 Jan 22 '18 at 2:28
• Not 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 Jan 22 '18 at 11:09
• @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 Jan 22 '18 at 20:49

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.

• A 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 Jan 22 '18 at 8:11
• @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 Jan 24 '18 at 11:50
• @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 Jan 25 '18 at 11:18
• That 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 Jan 26 '18 at 8:37

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.

• 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 Jan 30 '18 at 18:37

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.

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"

• 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 Jan 23 '18 at 5:47

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.)

• 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 Jan 22 '18 at 19:22
• @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 Is Fiddling By Firelight Jan 22 '18 at 19:55
• @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 Jan 24 '18 at 0:09
• 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 Jan 25 '18 at 2:41

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".

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?

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.

• 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 Jan 24 '18 at 11:33

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.

• 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 Jan 22 '18 at 19:20
• 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 Jan 22 '18 at 19:59
• 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 Jan 22 '18 at 20:50
• @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 Jan 23 '18 at 3:20

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.

• 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 Jan 22 '18 at 18:43
• 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 Jan 23 '18 at 14:37
• 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 Jan 24 '18 at 11:49

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.

• That'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 Jan 25 '18 at 13:27

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?"

• 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 Jan 22 '18 at 8:14
• +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 Jan 22 '18 at 10:08

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);
3


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

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


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.

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!

• Hi Jonny! Welcome to Computer Science Educators! 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 Jan 22 '18 at 2:30
• 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 Jan 22 '18 at 13:10
• 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 Jan 22 '18 at 17:38
• @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. – user4027 Mar 21 '18 at 20:41

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.

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. "

• I really like how this example shows abstraction in a fairly intuitive way, without having to directly define it – thanby Jan 25 '18 at 13:33
• 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 Jan 25 '18 at 18:53

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.

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.

• Not 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 Jan 22 '18 at 21:42

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 http://vpri.org/pdf/rn2005001_learning.pdf says it is a good way to teach about variables. The exercise is on page 2.

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.

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.

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.

• This answer would be probably better suitable as a comment to the question. – Maciek Łoziński Aug 19 '19 at 20:04

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.

• Welcome to Computer Science Educators! 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 Jan 22 '18 at 16:10

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

• Can you elaborate on how you'd explain it? I'm not sure what you mean by "as something that keeps changing" – thesecretmaster Jan 22 '18 at 12:57

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.

• No 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 Jan 22 '18 at 8:16
• 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 sciencedirect.com/science/article/pii/S1878929314000516 and excerpt taken from goodtherapy.org/blog/psychpedia/abstract-thinking – TryHarder Jan 22 '18 at 13:21