Variables: const
● Beginner2 min
const names a value that never changes after it is made.
fn main() {
const name = "Asha"
const limit: Int = 10
print("{name} may borrow {limit} books")
}The program ran and printed:
kavach run const.kav
Asha may borrow 10 booksChanging a const is refused before the program runs, with the fix in the message:
fn main() {
const price = 40
price = price + 2
print(price)
}The compiler refused the program:
kavach run let.kav
error: `price` is a `const`, so it can't change: declare it with `let`What Kavach does for you
const unless it must change
constvalues never change, and changing one is a compile error that says to uselet. You see at a glance what can move.