Skip to content

Constants and Globals

Constants use const and must be initialized immediately:

const APP_NAME: String = "Zap Demo";
const MAX_RETRIES: Int = 5;
fun main() Int {
const LIMIT: Int = 10;
return LIMIT;
}

Mutable top-level state uses global var:

global var destroyed: Int = 0;

Aliases let you name an existing type:

alias Score = Int;
alias Name = String;
alias Score = Int;
global var total: Score = 0;
fun add(points: Score) {
total = total + points;
}
fun main() Int {
add(10);
add(5);
return total;
}