TypeScript Course
TypeScript
/
Beginner

Basic Types

Definition

The primitive building blocks of the TypeScript type system: `string`, `number`, `boolean`, `null`, `undefined`, and `symbol`.

Explain Like I'm New

These are the fundamental labels you attach to your variables to tell TypeScript exactly what kind of data is allowed to live inside them.

Real World Example

Declaring a user profile: `let username: string = 'Alice'; let age: number = 25; let isActive: boolean = true;`

Common Use Cases

  • •Annotating primitive variables

Terminal Output

bash / terminal
const firstName: string = "Alice"; const age: number = 30; const isDeveloper: boolean = true; // Arrays of basic types const scores: number[] = [95, 80, 100]; const names: Array<string> = ["Alice", "Bob"]; // Alternative syntax

Interview Questions

basic

  • What are the three most common primitive types in TS?

intermediate

  • Should you use `Number` or `number` when typing?

advanced

  • What is the `bigint` type?

Flash Cards

Question

Should you use Number or number?

Click to reveal answer
Answer

ALWAYS use lowercase `number`, `string`, and `boolean`. The uppercase versions refer to the JavaScript wrapper objects, which you almost never want to use as types.