Skip to content

Console

The global console object is available in every program without an import. Each method prints a string followed by a newline.

console.log

Writes a string to standard output.

console.log("Hello, World!");
console.log("Zeus supports UTF-8 🚀");
let greeting: string = "Welcome to Zeus!";
console.log(greeting);

Output:

Hello, World!
Zeus supports UTF-8 🚀
Welcome to Zeus!

console.error and console.info

console.error writes to standard error; console.info writes to standard output. Both otherwise behave like console.log.

console.log("normal output"); // stdout
console.info("informational"); // stdout
console.error("went wrong"); // stderr

Logging byte arrays

A u8[] converts implicitly to string, so you can print raw bytes by assigning them to a string first:

let bytes: u8[] = new u8[];
bytes[0] = 'H';
bytes[1] = 'i';
let text: string = bytes; // u8[] -> string
console.log(text); // "Hi"