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: stringlet count = 42; // inferred: i32 (integer literals default to signed, ≥ i32)let ratio = 0.5; // inferred: f64let flag = false; // inferred: booleanThis 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-bitlet big: i64 = 100000000000; // explicit 64-bitlet x: i32; // no initializer — annotation requiredThe syntax is: let variableName: Type = value;
Default Values
Variables declared without an initializer receive type-appropriate defaults:
let x: i32; // Defaults to 0let y: f64; // Defaults to 0.0let b: boolean; // Defaults to false| Type | Default Value |
|---|---|
i8, i16, i32, i64 | 0 |
u8, u16, u32, u64 | 0 |
f32, f64 | 0.0 |
boolean | false |
| Object types | null |
Reassignment
Variables declared with let can be reassigned:
let counter = 0;counter = 1;counter = counter + 1; // counter is now 2Naming Conventions
Variable names must:
- Start with a letter or underscore
- Contain only letters, digits, and underscores
- Not be a reserved keyword
// Valid nameslet 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 keywordScope
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 scopeObject 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;