Chapter 6: Variables, Mutability, and Shadowing
Prerequisites
You will understand
letvslet mut— immutable by default- Shadowing is rebinding, not mutation
- Why Rust defaults to immutability
Reading time
20 min
+ 15 min exercises
Binding Cards
`let` vs `let mut`
Scope Diagram
Shadowing Creates New Bindings
Comparison
Shadowing vs Mutation Are Different Mechanisms
Watch the difference between shadowing and mutation directly in the stack frame.
Interactive simulation (requires JavaScript): shadowing creates a brand-new binding (allowing a type change from &str to u16) while the old one becomes unreachable; mutation with mut overwrites the same stack slot in place.