Foundations · chapter 1
1. Values & Types
The idea
Everything starts with values. TypeScript has one number type for both integers and decimals, so integer division is something you do (Math.floor), not a type you pick. Strings are immutable — every "change" builds a new one.
Cheat sheet
constby default,letonly when you reassign.varnever.numbercovers3and3.5;Math.floor(a / b)anda % bgive quotient and remainder.- Annotate function signatures:
function f(c: number): number. s.toUpperCase(),s[0]for the first character,+to concatenate.- Return two values as a tuple type:
[number, number].
Watch out
/always produces a decimal:7 / 2is3.5, never3.- Floating point is approximate —
0.1 + 0.2 !== 0.3. The tests usetoBeCloseTowhere decimals appear.
Memory hook
"const until it complains" — start every binding as const; the compiler tells you when you genuinely need let.
Red → Green → Refactor: run the tests first; each failing name tells you which function to bring to life.