Variables in Sway are immutable by default. This means that, by default, once a variable is declared, its value cannot change. This is one of the ways how Sway encourages safe programming, and many modern languages have this same default.
A variable declaration can contain a type annotation. A type annotation serves the purpose of declaring the type, in addition to the value, of a variable.
Let's take a look:
let foo:u32=5;
We have just declared the type of the variable foo as a u32, which is an unsigned 32-bit integer. Let's take a look at a few other type annotations:
let bar:str[4] =__to_str_array("sway");let baz:bool=true;
If the value declared cannot be assigned to the declared type, there will be an error generated by the compiler.