Variables are explicitly declared and used by the compiler to ensure types are correct. Variables' values are also mutable after they are declared. Variables MUST be declared with some value. The compiler will not assign a default value for you.
use fmt;
export fn main() void = {
let s = "This is a string";
fmt::println(s)!;
s = "now this is a new string";
fmt::println(s)!;
// Declare myage as an i32 and assign it the value 43
let myage: i32 = 43;
fmt::println(myage)!;
// Declare youage with the type definition as part of the value
let yourage = 39u64;
fmt::println(yourage)!;
};
$ hare run variables.ha
4/4 tasks completed (100%)
This is a string
now this is a new string
43
39
Back to table of contents