Programming Basics for Beginners

Free AI-generated illustrated lesson. Hand-drawn and narrated, step by step.

What is a Variable

What if I told you that a variable isn't a scary math equation, but just a physical box with a label? Inside this box, you can store anything you want to remember for later. Let's see how computers actually manage information.

Let's give our box a name, like score. Now we can drop a value inside it, like the number ten. This process is called declaring and assigning a variable.

In code, we write this with a simple equal sign. But watch out! This doesn't mean equal like in math; it is an action that means push this value into that box.

But here is the strange part: why are they called variables? Because the value inside can vary, or change, over time. Let's see what happens when our player scores some points.

If we add five to our score, we empty out the old ten and drop in a brand new fifteen. The old value is gone forever, replaced by the new one.

A common mistake is trying to write this backwards. In coding, the box name must always be on the left, and the value must be on the right.

Remember these three key rules. First, variables have a label. Second, they hold one value at a time. Third, the assignment flows from right to left.

Now you know how computers remember things! What kind of variable will you create in your first program?

Lessons in this 10-part set

  • What is a Variable
  • Loops in Programming
  • Functions Explained
  • Object-Oriented Programming
  • What is an API
  • Databases and SQL Basics
  • Conditional Statements
  • What is a Compiler
  • Version Control with Git
  • How Computers Store Data

Watch this free lesson — play it in My Magic Pencil.

▶ Watch free on My Magic Pencil