← TypeScript Foundations
4 / 25
Lesson 4 — Typed arrays
Arrays of one type
number[] means "an array that holds only numbers"; string[] holds only strings. TypeScript then knows the type of every item, so inside a loop n is a number and math on it is allowed. Pushing the wrong type is an error.
const names: string[] = ["Ann", "Bo"];
for (const n of names) console.log(n.toUpperCase());
// names.push(5); ← error
Why it matters: lists are everywhere, and a typed list guarantees every item can be used the same way.
Want it another way?
Task
Add every number in nums to sum so the program prints 60.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
Test your knowledge
A quick 3-question quiz on this lesson — instant feedback.