lesson

Updated 1 month ago · 3 views
Imagine playing a video game where every time you collect a coin, the game instantly forgets how many you have.
To track high scores, player names, and remaining health, computers need a dedicated place in memory to hold onto information while a program runs.
What Is a Variable?
A variable is a named storage container in computer memory that holds one piece of data at a time.
Think of it like a labeled box: the label tells you what belongs inside, and the value inside can be looked at or changed whenever your program needs.
📊Interactive diagram
What different types of information can we actually store inside these memory boxes?
Storing Different Kinds of Data
Variables can hold numbers, written words called a string (wrapped in quotation marks), or simple true-or-false flags called a Boolean.
📊Interactive diagram
If a game uses dozens of variables at the same time, how do we keep them from getting hopelessly mixed up?
Labeling Variables Clearly
A good variable label is descriptive, meaning anyone reading your code instantly understands exactly what information is stored inside.