Variables and Primitive Types
AvailableLesson 1 of 25 · Syntax · Easy
The big idea
A variable stores a value so your Rust program can remember and use it. In Rust, you create a variable with the word let, a name, an equals sign =, a value, and a semicolon ; at the end: Rust figures out the type automatically, and keeps variables locked so they do not change by accident (add mut later when you want to change one).
Think of it like this: Think of `let` in Rust like putting a value in a sealed, labeled jar: `let x = 5;` labels the jar `x` and puts `5` inside.
Read the lesson
A variable stores a value so your Rust program can remember and use it.
In Rust, you create a variable with the word let, a name, an equals sign =, a value, and a semicolon ; at the end:
let age = 20; // a whole number (i32)
let price = 9.99; // a decimal number (f64)
let name = "Maya"; // text (&str)
let is_ready = true; // true or false (bool)
Rust figures out the type automatically, and keeps variables locked so they do not change by accident (add mut later when you want to change one).
Quick check
Which line creates a variable named age set to 20 in Rust?
Your challenge
Inside main(), create a variable named x and set it to 5 (type let x = 5;).
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to python.variables-types (85% overlap). Variables & primitive types: compare let/const (JS), auto/int (C++), := (Go), let mut (Rust), and column types (SQL).
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Variables and Primitive Types.
Learn this first
Nothing needed - you can start here.