GCGrowCarrer

Variables and Primitive Types

Available

Lesson 1 of 25 · Syntax · Easy

Mastery0% of 85%
1

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.
Key words (tap to learn):
2

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).

3

Quick check

Which line creates a variable named age set to 20 in Rust?

4

Your challenge

2 sample tests, 1 hidden

Inside main(), create a variable named x and set it to 5 (type let x = 5;).

Stuck? Get a hint (free)
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.

Mastery0%

Learn this first

Nothing needed - you can start here.