Portmint Lighthouse
Coding Basics

What Is a Variable? (Coding for Absolute Beginners)

If you have ever heard programmers talk and thought, "What on earth is a variable?" — you are in exactly the right place. No prior knowledge needed. By the end of this short read, you will understand one of the most basic building blocks of all code.

Let's start with the plain idea, then I'll hand you one everyday picture to hold onto.

The Plain Idea

A variable is a named place where a computer stores a piece of information so it can use it later.

That's it. Two parts:

  • A name — the label you give it.
  • A value — the information it holds.

The information could be almost anything: a number, a word, a yes-or-no answer, a date. The variable's job is simply to remember that value for you, so the program can look it up whenever it needs to.

One Everyday Picture: A Labelled Box

Imagine you are tidying a closet, and you grab a cardboard box. You write a label on the front with a marker — say, "winter hats" — and you put your winter hats inside.

That box is a variable.

  • The label ("winter hats") is the variable's name.
  • The stuff inside (the hats) is the variable's value.

Now, here's why the label matters: you don't have to remember where the box is or what's in it. You just read the label. If someone asks for a hat, you walk over to the box marked "winter hats" and open it. The label points you straight to the contents.

Computers work the same way. Instead of juggling a raw piece of information everywhere, the program tucks it into a labelled box and refers to it by name. When the code says age, the computer knows to go find the box labelled "age" and look inside.

Why "Variable"? Because the Contents Can Change

The word variable comes from vary — to change. And that's the clever part of the box: you can empty it out and put something new in, while the label stays the same.

Picture a box labelled "score" in a simple game.

  • At the start, the box holds the number 0.
  • You win a point, so someone empties the box and puts 1 inside. The label still says "score."
  • You win again — now the box holds 2.

The name never changed. The contents did. The program can keep checking the box labelled "score" at any moment and always get the most up-to-date number.

This is enormously useful. It means a program can be written once but work with information that keeps changing — your score, the time of day, how many items are in a shopping cart. The code just keeps reading the boxes, and the boxes hold whatever the latest value happens to be.

A Quick Mental Walkthrough

Here is a tiny, made-up sequence in plain English — no real code, just the idea:

  1. Make a box and label it "name." Put the word "Sam" inside.
  2. Make another box labelled "age." Put the number 34 inside.
  3. Later, the program wants to greet someone. It reads the "name" box, sees "Sam," and prints "Hello, Sam!"

The program never had to know the name was Sam in advance. It just trusted that whatever was in the box labelled "name" was the value to use. Swap "Sam" for "Maria," and the greeting becomes "Hello, Maria!" — no other changes needed.

That flexibility is the whole point.

Keep Going

You just learned the single most reusable idea in all of programming. Almost everything else — adding numbers, making decisions, repeating actions — builds on top of these labelled boxes. 🔦

So if variables now feel a little less mysterious, that's real progress. Take a breath, let it settle, and come back for the next idea whenever you're ready. One small concept at a time is exactly how every programmer started — including the ones who seem to know everything today.

Keep going with Pip

Ready to write your first real code? Pip's Programming, from Zero course starts at the very beginning — one friendly lesson at a time.

Take Pip's Programming, from Zero course →