Skip to main content

Program Structure

Every program must define a main function, which acts as the starting point of execution. This makes it immediately clear where the program begins, keeps the codebase more organized, and allows other readers to locate the core logic.

fn main() {
console.log("Hello, world!");
}

No Top-Level Function Calls

Function calls aren't allowed in the global scope; all executable code must be placed inside functions. This prevents unexpected behavior during startup, promotes modular design, and keeps the program’s flow easy to follow.

console.log("This won't work");  // ❌ Not inside a function
fn main() {
console.log("This is fine"); // ✅ Inside a function
}