Skip to content

Variables

Variables in Zeus are statically typed. The type can either be written explicitly or inferred by the compiler from the initializer.

Declaration

Use the let keyword to declare mutable variables:

let age = 25;
let temperature = 98.6;
let isActive = true;

Use const for immutable values:

const PI = 3.14159;
const MAX_SIZE = 100;

Type Inference

When you provide an initializer, Zeus infers the type automatically:

let name = "Zeus"; // inferred: string
let count = 42; // inferred: i32 (integer literals default to signed, ≥ i32)
let ratio = 0.5; // inferred: f64
let flag = false; // inferred: boolean

This is the preferred style for local variables — it keeps code concise without sacrificing safety. The type is still checked at compile time; you just don’t have to write it.

Explicit Type Annotations

When you need a specific type — a larger integer size, a signed type, or you’re declaring without an initializer — add the annotation after a colon:

let small: i8 = 127; // explicit signed 8-bit
let big: i64 = 100000000000; // explicit 64-bit
let x: i32; // no initializer — annotation required

The syntax is: let variableName: Type = value;

Default Values

Variables declared without an initializer receive type-appropriate defaults:

let x: i32; // Defaults to 0
let y: f64; // Defaults to 0.0
let b: boolean; // Defaults to false
TypeDefault Value
i8, i16, i32, i640
u8, u16, u32, u640
f32, f640.0
booleanfalse
Object typesnull

Reassignment

Variables declared with let can be reassigned:

let counter = 0;
counter = 1;
counter = counter + 1; // counter is now 2

Naming Conventions

Variable names must:

  • Start with a letter or underscore
  • Contain only letters, digits, and underscores
  • Not be a reserved keyword
// Valid names
let userName = 1;
let _private = 2;
let count2 = 3;
// Invalid names
// let 2count = 4; // Cannot start with digit
// let my-var = 5; // Hyphens not allowed
// let let = 6; // Reserved keyword

Scope

Variables are scoped to the block they’re declared in:

let outer = 10;
if (outer > 5) {
let inner = 20;
// Both outer and inner are accessible here
}
// Only outer is accessible here
// inner is out of scope

Object Variables

When declaring object variables, the type is inferred from new:

class Point {
public x: i32;
public y: i32;
}
let p = new Point();
p.x = 10;
p.y = 20;

Object variables can be assigned null (explicit type annotation required in that case):

let p: Point = null;