Lesson 4 +10 XP

Primitive Types in TypeScript

Primitive Types

TypeScript supports JavaScript's primitive types: number, string, boolean, symbol, and bigint.

Overview of Primitives

TypeExamplesDescription
number42, 3.14, 0xFFFloating point numbers and integers.
string"hello", 'world', `` sum: ${x} ``Textual data and template literals.
booleantrue, falseLogical truth values.
bigint100n, BigInt(9007199254740991)Arbitrarily large integers.
symbolSymbol("id")Unique and immutable primitive values.

Array & Tuple Primitives

Arrays can be typed using array syntax type[] or Array<type>.

let scores: number[] = [90, 85, 95];
let names: Array<string> = ["Alice", "Bob"];

// Tuple: fixed-length array with specified types at each position
let tuple: [string, number] = ["Alice", 25];

TL;DR

  • Always use lowercase primitive type names (number, string, boolean), not upper-cased wrappers (Number, String).
  • Tuples define fixed-length arrays with distinct element types at each index.