Curriculum Foundations Bindings and mutability exercise 4 · mcq
Bindings and mutability
The program parses a string and wants to use the same name
n for the parsed integer. The type changes from &str to
i32, so mutation can't do it — pick the right Rust shape.
About this theme
Rust flips TypeScript's mutability default. Every binding starts immutable; you opt in to mutability with let mut. Type annotations come after the name (let x: i32 = 5), and the numeric primitives are width-specific (i32, u64, f64) instead of TS's single number. Shadowing is allowed and idiomatic because it creates a fresh binding that happens to reuse the name. Planned exercises: 1. choose immutable let. 2. choose let mut. 3. recognise type annotations. 4. distinguish mutation from shadowing. 5. fill mut. 6. fill a type annotation. 7. write a rebinding line. 8. translate several TS bindings. 9. fix a program that tries to mutate an immutable binding.