A variable is a way to store values into your programs, and to refer to them using meaningful names.

Suppose you have the number “5” and you want to give it a special meaning.

For example, the age of a child.

You can assign it to a variable. The exact syntax depends on the programming language, but in general terms you can imagine it being

childAge = 5

In JavaScript for example you would use

let childAge = 5

(read it as “let childAge be 5”)

Now you could use the childAge variable, which has the 5 value assigned, in other operations. Like printing:

print childAge
//this prints "5" to the screen

(I’m still using pseudocode)

Now, a variable can typically change its value.

If it’s the child birthday, you can change the value to

childAge = 6

Variables are an essential part of programming.

One thing that’s very important is naming your variables in the right way. As with many things, there’s no “one true way” of doing it. It also depends on your team, if you will work on a team. But one thing that is more or less universal is that it’s important to give variables a meaningful name, so that when you look at them in your programs, they can infer their meaning while you read the code.

childAge is a good example - it’s the age of a child.


Go to the next lesson