Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

Part 3.2Arrays, tuples and readonly data

Arrays

Put the element type before [] to describe an array. This makes accidental mixed collections obvious.

TypeScript
const scores: number[] = [12, 19, 25];
const names: Array<string> = ["Ada", "Lin"];

Tuples

A tuple describes a fixed-length collection where each position has a known type. It is ideal for small values such as coordinates.

TypeScript
const location: [number, number] = [55.9533, -3.1883];

Readonly data

Use readonly string[] for an array that a function may inspect but must not change. This lets a caller pass either a mutable or readonly array while keeping the function honest about mutation.

Feedback 👍
Comments are sent via email to me.