📝 Variables in Rust: Simple, Safe, and Powerful


✨ Declaring Variables

rust
Loading…
  • let creates a variable (immutable by default)
  • mut makes it mutable (you can change it)
  • You can add a type (like f64) if you want

🔄 Changing Values (Mutability)

rust
Loading…

🕵️ Shadowing: Reuse Names, Change Types

rust
Loading…
  • Shadowing lets you reuse a variable name
  • You can even change its type!

🧠 Best Practices

  • Prefer immutability (let) unless you need to change the value
  • Use clear, descriptive names
  • Shadowing is great for transformations
  • Type annotations are optional, but can help with clarity