TypeScript · module 2 of 21
Primitive Types
TypeScript's core primitives are string (text), number (any numeric value — int, float, hex), and boolean (true/false).
What this module covers
4 steps · TypeScript
Step 1. Primitive Types
TypeScript's core primitives are string (text), number (any numeric value — int, float, hex), and boolean (true/false). let name: string = "Ruth"; let age: number = 22; let hex: number = 0xFF; let isActive: boolean = true; Special types: - any — disables type checking entirely (avoid when possible) - unknown — a safer version of any; requires a check before use - null and undefined — their own types - void — for functions that return nothing - never — for functions that never return (e.g. always throw) Type inference: TypeScript can guess types automatically (let x = 10; infers number), but explicit annotations are still good practice for clarity.
`any` opts a value out of type checking entirely, while `unknown` still forces you to narrow the type before using it — prefer `unknown` whenever you genuinely do not know the shape yet. In TypeScript, make the state/interaction visible in the UI so completion is easy to verify.
Check yourself: [TypeScript] Add a variable typed `any` and a variable typed `unknown`.
Step 2. Quiz: Primitive Types
Answer these questions about primitive types.
string, number, and boolean are the three core primitives; any and unknown handle values whose type is not known up front. In TypeScript, make the state/interaction visible in the UI so completion is easy to verify.
Check yourself: [TypeScript] Answer the quiz below.
Step 3. Type All Primitives
Declare variables for each of the following types: city as a string, population as a number, isCapital as a boolean, nothing as null, notAssigned as undefined, wild as any, data as unknown.
Every JavaScript primitive has a matching TypeScript type — practicing all of them together builds the muscle memory for reading real type signatures later. In TypeScript, make the state/interaction visible in the UI so completion is easy to verify.
Check yourself: [TypeScript] Does every variable use the correct primitive type?
Step 4. Mini project: Primitive Types
Declare variables for each of the following types: city as a string, population as a number, isCapital as a boolean, nothing as null, notAssigned as undefined, wild as any, data as unknown. Turn the completed challenge into a small standalone project. Add realistic content, clear naming, one edge case or error state, and a short README-style explanation of how the main idea works.
Every JavaScript primitive has a matching TypeScript type — practicing all of them together builds the muscle memory for reading real type signatures later. This project stage asks you to apply the same idea without step-by-step scaffolding. In TypeScript, make the state/interaction visible in the UI so completion is easy to verify.
Check yourself: [TypeScript] Does every variable use the correct primitive type?
Loading code lab...