lesson

Updated 6 days ago ยท 1 view
When you play a video game, how does the computer remember how many coins you collected?
The computer uses a special storage box in its memory called a variable.
๐Interactive diagram
What makes these memory boxes so special in coding?
The Labeled Box
A variable is a named container that holds a value while a program runs.
Every variable has two main parts: a name on the outside so the computer knows which box to grab, and a value stored safely on the inside.
๐Interactive diagram
What happens to the box when you collect another coin in the game?
Values Can Change
The word variable comes from the word 'vary', which means to change.
The box keeps the exact same label, but you can swap out the old item inside for a brand new one.
๐Interactive diagram