# How to Teach Variables to Kids

Last Updated: April 5, 2023 2:00 pm
How to Teach Variables to Kids

You can think of programming variables for kids as a box that contains something. You can open the box to find out what is inside, or even put something else into the box. In some ways, human memory and computer memory are similar. We rely on our memory for remembering all sorts of things.

This idea can help clarify the variable definition for kids.

For example, while watching a basketball game, we remember the current score. Now, in computer-speak, that’s a variable that holds a number such as 84 and changes over time as more baskets are scored. My favorite ice cream flavor? That’s another variable that holds a value, such as butterscotch. The types of variables in programming can hold numbers, fractions, and phrases.

So, how exactly do computers store, organize, and retrieve this information? Let’s take a look at some simple coding variables!

## What is a Variable?

A variable is like a labeled container in the computer’s memory where you can store values or data. In most programming languages, a variable can store a single value type. Usually, these are numbers, fractions, or phrases. The kind of value that a variable can hold is also called a data type. Now, let us look at 3 data types – Numbers, Strings, and Booleans.

## What are all the Types of Coding Variables?

Numbers
A number is one of the simplest data types. Programming languages have different kinds of numbers. Integer variables can hold numbers like 5 or -3. For holding fractional values, some programming languages have special types to hold fractional values like 3.14.

For example, here is a variable in use in Tynker:

score is a variable with a value of 0 when the program starts. According to the program above, it looks like every time a candy is found, score is incremented by 1. So, if five candies are found, score will have the value 5.

Strings
Strings are variables used to represent text. Strings hold groups of characters, like a word or a phrase. An easy way to think about strings in real life is to think about how your brain stores information. Think about a person as a variable. A name is simply a value that your brain uses to identify that person.

To practice using strings, suggest these variables that your child can add values to and use them later in a sentence.

Name:

Animal:

Day:

Place:

What would this  sentence be if your values are “Michael,” “bunny,” “Sunday,” and “park”?

“<Name> chased the <Animal> all the way to the <Place> on <Day>”

What if your sentence is:

“The <Animal> chased <Name> all the way to the <Place>!”

Booleans
A Boolean contains the value true or false. Booleans are truth values–they’re a data type that can represent one of two outcomes: true or false. Booleans answer yes-or-no questions, and Boolean functions are used to perform tests. In a video game, you might test if a player has walked into an obstacle, or if their health is equal to five.

Do this fun unplugged activity with your child to teach them about Booleans! Tell your child to think of their favorite animal (or other favorite thing, such as a favorite food or favorite book. Make sure it’s something that you would know about!). Then, tell your child that you are going to ask them true/false questions to guess what the item is (and that they can’t change the item). After they have thought of the item, ask them a series of true/false questions and try to guess the item. Remind your child that they can only answer true or false! Explain to your child that they are functioning like a computer when they hear your true/false question (the input), think about the right answer, and then provide an output of true or false.

If you are a teacher, you could have students ask each other true/false questions. An alternative activity is to write a variety of questions (not just ones that can be answered by true/false) on index cards. Hold up each card to students and have them identify whether each one can be answered with true or false or not. Reinforce that questions that can be answered by true or false are Boolean expressions.

There are more complex data types beyond numbers, strings, and Booleans. For example, if you want to store a picture, a large document or a list of contacts, you need more complex data types to hold that information.

## Variables in Math

While math variables and coding variables share some similarities, there are some key differences. In math, variables are usually used to represent unknowns or to solve equations. In coding, variables are used to store and manipulate data.

In math, the value of a variable is typically calculated through equations, while in coding, the value of a variable is assigned by the programmer. Additionally, math variables tend to be represented by letters, while coding variables can be given any name that follows certain rules.

Another difference is that math variables are usually constants, meaning that their value does not change. In contrast, variables in coding can change, allowing programmers to manipulate and update the data stored in them.

Overall, variables in coding are an essential tool for storing and manipulating data in a program. Unlike math variables, coding variables can change and be updated, allowing programmers to create more dynamic and interactive programs.

## What is an example of a Variable in Code?

In text coding languages like JavaScript, these are how variables are used:

Here, myName and myAge are variables and “Jeremy” and 14 are the values they contain. So the alert command would print:

Hi, I’m Jeremy and I am 14 years old.

## Why are Variables Important in Programming?

Variables in coding are vital components of programming that enable the storage, manipulation, and management of data. They play a central role in data processing, allowing developers to work with diverse data types efficiently. In essence, coding with variables empowers programmers to create adaptable and dynamic software that can respond to changing inputs and conditions.

Moreover, variables in programming enhance code readability by providing descriptive labels for data elements. This clarity simplifies the understanding of code, making it more accessible to both developers and collaborators. Variables coding also promotes code reusability, as data stored in variables can be utilized across various parts of a program, reducing redundancy and enhancing maintainability.

## Importance of Kids Learning Variables

Learning variables in programming is important for kids because it teaches them how to store and manipulate data in a program. Variables are like containers that hold information that can be accessed and changed over time. Additionally, learning variables helps kids understand how computer memory works and how information is stored and retrieved. Overall, understanding variables in programming is an essential foundation for kids who want to learn how to code and build their own projects.

In Tynker courses such as Goblin Quest, students learn about these variables and apply them as they build several hands-on coding projects such as Memory Game, MadLibs greeting cards, Geography Quiz, The Never-Ending Story, and more.

## Related Searches:

### About Tynker

Tynker enables children to learn computer programming in a fun and imaginative way. More than 60 million kids worldwide have started learning to code using Tynker.