Skip to content

Variables and types

Goal: Annotate values and let the compiler catch mismatches.

Use const by default; let when reassignment is required. Primitives: string, number, boolean.

Example

const pi: number = 3.14
let count: number = 0
count = count + 1

const label: string = "items"
const ok: boolean = count > 0

Open in playground

Key takeaways

  • const bindings cannot be reassigned.
  • Annotations are optional when inference is obvious.
  • SJS-E001 fires on type mismatches.

Next: Functions

Documentation