Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Basic Types · Lesson 4 of 12

Primitive Types

A free lesson from Swipe Coding · TypeScript, level 2 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
Three little words — string, number, boolean — and you've basically got JavaScript's whole value system covered. 🧩

TypeScript's most basic types map directly onto JavaScript's primitive values: string for text, number for all numbers, and boolean for true/false. Each one is written in lowercase, right after a variable's name.

let username: string = "amara";
let score: number = 87;
let isActive: boolean = true;
Each annotation matches the kind of value the variable is meant to hold — TypeScript will only ever allow that variable to be reassigned to a value of the same type.
🤖
No int-vs-float headaches here — TypeScript keeps numbers refreshingly simple. 🔢

number covers every numeric value in TypeScript — whole numbers, decimals, negatives — there's no separate int, float, or double the way there is in some other languages. JavaScript only has one numeric type under the hood, and TypeScript matches that.

let price: number = 19.99;
let temperature: number = -4;
let quantity: number = 12;
Whole numbers, decimals, and negatives are all just number — TypeScript doesn't distinguish between them the way languages like Java or C# do.

string covers any text, written with single quotes, double quotes, or backticks for template literals — TypeScript doesn't care which quoting style you use, only that the value is text.

let city: string = 'Nairobi';
let greeting: string = `Hello, ${city}!`;
Both variables are typed string, whether the value was written with single quotes or built with a template literal.
Fill in the blank

let isActive: ____ = true; is the correct annotation for a variable that only ever holds true or false.

Quick check

Which type would you use to annotate a variable that holds the value 3.14?

True or false

TypeScript has separate int and float types for whole numbers and decimals.

Keep your streak going in Swipe Coding

Swipe through every level of TypeScript on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →