Every program has to remember things: your name, what's in your basket, how many tries are left. It keeps each one in a variable.
In a kitchen pantry, each jar has a label. The label says “rice”. Today it’s full of rice. Next week you might tip it out and fill it with lentils, but the label stays and you still know where to look.
A variable is that jar inside a program. It has a name and holds one piece of information. The program can look inside, use what’s there or empty it and put something new in.
What a variable looks like
In code it’s often just one line:
- name = "Priya": a jar called name holding a word
- age = 34: a jar called age holding a number
- basketTotal = 59.99: a jar called basketTotal holding a price
When you add something to your basket, the program changes what’s in basketTotal. The name stays the same; only what’s inside changes.
Why programs need them
Without variables a program couldn’t remember anything from one moment to the next. It couldn’t keep your score in a game, the words you typed into a form or how many items are in your basket.
Where the comparison breaks down
A jar holds lots of rice. A variable usually holds one value at a time. Some hold a whole list, like a jar of labelled envelopes, but each envelope still holds just one thing.
How the words fit together
Variables are one of the basic building blocks of code. All the variables in an app at one moment are its state. A variable holding the wrong thing is a classic bug, and JSON is a common way to save many variables at once.
Good programmers give variables clear names, like basketTotal instead of x. Code is read far more often than it is written.

When you'll hear it
“It's stored in a variable.” The program put that value in a named spot so it can use it again.
“That variable is empty.” The spot exists but nothing has been put in it yet, which often causes a bug.
“Make it a constant.” A variable that's never allowed to change, like a jar that's sealed.
“What does the app need to remember about each customer, and for how long?”


