Reference

Programming languages

Choose TypeScript, Go, Rust or C++ and find syntax, everyday APIs, standard libraries and tools in one place.

Scope and conventions

TypeScript/Node, Go 1.23+, Rust 2024 and C++23: from a first CLI to files, JSON, HTTP, concurrency and testing. Complete programs are labeled; other examples identify their surrounding code/imports. Optional libraries and version requirements are named in each entry.

Functions

Define and call a function

TypeScript

Parameters use name: type; the return type follows ). Call with parentheses. An arrow is another function form; void means no useful return value.

Fragment

Function declaration and call.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
function double(n: number): number {
  return n * 2;
}

const result = double(6);

Find the entry point

TypeScript

Node evaluates top-level code; main is a chosen name, not a required entry point. async returns a Promise. void discards that Promise value; it does not catch rejection.

Fragment

Complete Node program.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
async function main() {
  console.log("north");
}

void main();

Recognize custom types and methods

TypeScript

class defines a runtime type; new constructs it. this addresses the instance. private restricts TypeScript access. User-defined class and method names are application APIs, not TypeScript keywords.

Fragment

Complete custom declaration and use.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
class Counter {
  private value = 0;

  add(): void {
    this.value += 1;
  }
}

const counter = new Counter();
counter.add();

Construct a custom value

TypeScript

new calls a class constructor to initialize an instance. this refers to that instance. A type alias or interface has no runtime constructor; an object literal can create a value with that shape.

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
class Token {
  value: number;

  constructor(value: number) {
    this.value = value;
  }
}

const item = new Token(24);

Pass a function or capture a value

TypeScript

Functions are values. An arrow can capture variables from its surrounding scope and uses lexical this. Capturing a mutable binding does not take a frozen snapshot of its value.

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const factor = 3;
const scale = (n: number) => n * factor;

const result = [2, 5].map(scale);

Recognize defaults and variable arguments

TypeScript

Default parameters apply when the argument is omitted or undefined. A rest parameter collects remaining arguments into an array. Spread expands an iterable at a call; it is not the same operation as a rest declaration.

Fragment

Fragment: imports and type/function declarations at file scope; usage statements inside a function.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
function label(name = "guest", ...tags: string[]) {
  return [name, ...tags].join(":");
}

const text = label(undefined, "new", "blue");