Skip to content
Learn Netverks

Lesson

Step 6/36 17% through track

variables-mutability

Variables and mutability

Last reviewed Jun 1, 2026 Content v20260601
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
beginner

This lesson

This lesson teaches Variables and mutability: the syntax, APIs, and habits you need before advancing in Rust.

Teams ship Variables and mutability on every Rust codebase—skipping it leaves gaps in debugging and code reviews.

You will apply Variables and mutability in contexts like: Infrastructure CLIs, proxies, game engines, blockchain nodes, and latency-sensitive backends.

Write Rust with fn main(), click Run on server—the dev runner compiles main.rs with rustc and runs the binary; fix borrow errors from stderr (requires Rust toolchain; LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

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

  1. Q: Why immutable by default?
    A: Easier reasoning and fewer accidental mutations—opt into mutability explicitly.

Self-check

  1. What keyword makes a binding mutable?
  2. 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.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Community stories on this track

Learner essays linked to Rust — not official lesson content.

Browse all stories

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • let vs let mut?
  • Shadowing use?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump