πŸ“¦
World 3 Β· Building Blocks

Variables: Labeled Boxes

Imagine you have a stack of boxes. On each box you write a name with a marker, then you tuck something inside. Later, whenever you say the box’s name, you get back what you put in it. In Rust, those boxes are called variables. πŸ“¦

Making a box with let

To make a variable, you use the magic word let. You give the box a name, then an equals sign =, then the value you want to store inside.

let age = 10;

This says: β€œMake a box called age and put the number 10 inside.” The semicolon ; at the end is like a period at the end of a sentence β€” it tells Rust you’re done with that instruction.

New word A variable is a named box that holds a value. You look inside it by using its name.

Looking inside the box

Once you’ve put something in a box, you can print it. To pop a variable’s value into your message, use curly braces {} like a little window into the box.

See how {name} turned into Ferris and {age} turned into 10? Rust peeked inside each box for you and dropped the value right into your sentence. πŸŽ‰

Think of it like this… A variable is like a labeled locker. You don't have to remember exactly what is inside β€” you just find the one with the right name and open it.
Try this! Add a new box called color and store your favorite color in it, like let color = "blue";. Then print a line that uses {color}. Press β–Ά Run!

Quick quiz

What does let score = 7; do?

Yes! let makes a named box (a variable) and stores a value inside it. πŸ“¦

You learned… A variable is a named box made with let. You store a value inside and grab it later by name, and you can print it with {}. Next up: what happens when you want to change what's in a box! πŸ”’