Rust variables are immutable by default. Use mut when you need to reassign. This differs from JavaScript's let vs const and Java's always-reassignable locals unless final.
Declarations
let x = 5; // immutable
let mut count = 0; // mutable
count += 1;
Shadowing
let x = 1; let x = x + 1; creates a new binding—useful for transforming values without mut.
Important interview questions and answers
- Q: Why immutable by default?
A: Easier reasoning and fewer accidental mutations—opt into mutability explicitly.
Self-check
- What keyword makes a binding mutable?
- How is shadowing different from mutating?
Tip: Immutability is the default—add mut only when reassignment is required. Shadowing with let is not the same as mutation.