Concept of Variables For Kids
Concept of Variables For Kids
Where do you store your things? Salt and Sugar in containers? Toys in a
box? or wherever you would like to. Storing is a common task that we all
do in different ways. I am sure you must have thought of many other
examples. In the programming language, Variable is our container that
we use to store different types of information. The best way to understand
any programming concept is to imagine its functionality in our daily life.
Let us understand the variables with an example:
Monu is a 9-year kid. He always checks his height on his birthday and
records it in his diary. Every year when his height increases he cuts the
last value and writes the new one. So, What is the variable here?
I hope you can guess that the diary is variable here. Why? because we are
storing information in it and we can vary(change) the information we
store in it.
What will we learn?
1. What is a Variable?
2. What role do name and value play in a variable?
3. Why are Variables important?
4. How to create a Variable?
5. Different types of variables?
Integers
Strings
Arrays
Booleans
6. Conclusion
What is a Variable?
In simple language, Variable acts as a Container to store a value that can
be manipulated(changed). The data stored in variables can be used
throughout your program.
Let us understand this with an example. You can even try this with
anyone: let's say you are thirsty, so you asked for a glass from your
mother. This is a clear glass, and you can see that it is empty. It is simply
the storage container for the liquid you choose to put in it. In this
example, your cup acts just like a variable, and the liquid you put into it
is a value.
The cup looks different when it is holding coffee vs. juice vs. water, but it
is just the value inside that is changing. Similarly in a variable, we can
keep the same name and change its value whenever we want.
and Orange Juice, water, coffee are different values for this variable
Imagine you are going to shift to a new home. You packed all your
belongings in the boxes like all toys in one box, Books in another box,
but irrespective of what that box has inside you named them randomly.
Now it's your class test and you want your books box but many boxes are
lying there. Which one is your book box? You picked up the box that has
books slip on it but when you open it you get toys inside. Now can you
imagine how much short our work would have been if your box name
was meaningful to things it has inside?
1. String
Think about the way you remember the names of the people around you.
A name is just like a string: it is a value made up of characters (letters)
that your brain stores and uses to identify another person. Similarly, you
can use a string in programming to label and store values in your code.
Strings make communication easy for us. Now try to find some strings
near you. You must have got many things in your mind like your name,
and the best example is the line you are reading this is nothing but a
bunch of strings.
2. Integers
Imagine you are the football captain of your team, and you want to add
up the number of goals your team scores in each game in a particular
season. First, you would store the number of goals scored in each game
of that season as integer variables. Next, You will add up all the variables
together to know the total goals in the season.
3. Booleans
Let us play a game together. You have to answer some questions and you
have to follow the only rule that is you have to answer by saying True(if
you think it's correct) or False( If you think it's wrong).
It's okay if you don't know some answers at least you tried. The main
motive behind this small Quiz was to tell you that the questions that can
be answered using True/False are Boolean Expressions.
Let us not get deep into this just remember if we want to store integer
value, String value, etc in a single variable Array is used for that purpose.
Conclusion
Hence, We concluded that variables play an important role in making our
program flexible. Variable has name and value. We should choose a
meaningful name of the variable for better understanding. Using variables
enables us in writing flexible programs. There are different types of the
variable we have are strings, Integer, array, and boolean. There are many
other complex data types we have but for basic understanding, these are
enough.
Remember to relate everything around you with the variable for better
understanding.