Batting order
A list of players. Any length, any order.
When the openers walk out, they walk out in a specific order. Number 3 follows. The captain might come in at 4 or 5. That order is a list — a collection of players where each spot matters, and where you can swap, add, or drop names freely.
TypeScript calls that an array. A list of any length, of the same kind of thing. Five player names. Eleven. Fifty. All string[] — “array of strings.”
Tap a player, then tap another to swap them. Watch the lineup change live — that's the array, updating in place.
The lineup is an array.
Any length. Any order. Add, remove, reorder — TypeScript trusts you to know what's in the list.
// The batting order — any length, any order const order: string[] = ['Sharma', 'Iyer', 'Pretorius', 'Pierre', 'Singh']; // Whoever is at position 0 is on strike const onStrike = order[0];
An array is a list that can change.
You just edited a string[] — an array of strings. You can swap, push a new name, pop the tail off, or sort the whole thing. The length isn't fixed, and TypeScript only cares that every element is still a string.
Up next: what happens when the collection has to be exactly two — the partnership at the wicket. That's a tuple, and TypeScript treats it very differently.