var (Mutable Binding)
var declares a mutable binding, whose value can be reassigned later. Use var when you genuinely need to modify a variable's value.
Mutability is a choice, not the default behavior. You need to explicitly write var to indicate that this variable may change, which helps readers quickly identify where state is modified in the code.
The code on the right demonstrates the use of mutable bindings count and message. The compiler tracks variable mutability: if you declare with var but never reassign, it will suggest using let instead. Try changing var count on line 2 to let count and observe where the compilation error appears after running.
Note
If a variable is never reassigned after declaration, the compiler may issue a warning suggesting to change it to
let.