Variable and Mutability

By default, variables are immutable. Although variables are immutable by default, you can make them mutable by adding mut in front of the variable name.

Note: you should be careful about this while switching from Javascript or Typescript

let x = 1; // immutable
let mut y = 2; // mutable

Constants

Like immutable variables, constants are values that are bound to a name and are not allowed to change, but there are a few differences between constants and variables.

const THREE_HOURS_IN_SECONDS: u32 = 60 * 60 * 3;

The compiler is able to evaluate a limited set of operations at compile time, which lets us choose to write out this value in a way that’s easier to understand and verify, rather than setting this constant to the value 10,800.

Shadowing

You can declare a new variable with the same name as a previous variable.

Loops

Rust has three kinds of loops: loopwhile, and for.

loop

The loop keyword tells Rust to execute a block of code over and over again forever or until you explicitly tell it to stop.