CricketScript Lesson 2 of 11 · Batting order  |  Course

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.

Tap a player, then tap another to swap them.
on strike Sharma

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.

Lesson 3 — At the wicket →
Reading a paid lesson? The rest is right here.

This is one of 9 paid lessons. Lessons 1 and 9 are free previews if you want to sample first — otherwise the full course unlocks in one click.

$15worldwide · ₹625India (50% off)
Unlock all 11 lessons + bonus →
30-day money-back guarantee · Try Lessons 1 and 9 free first if you'd rather
Made by one person, not a company. Questions: hello@cricketscript.dev