JavaScript Tutorial: Data Types
string, number, boolean, null, undefined, symbol, bigint — and the coercion traps that catch everyone.
Everything has a type
JavaScript has seven primitive types. Understanding them — and especially how JavaScript converts between them automatically — saves you from some of the most confusing bugs in the language.
The famous `"5" + 1 = "51"` trap? That's type coercion. You'll learn exactly why it happens and how to avoid it.
What you'll learn in this JavaScript data types tutorial
This interactive JavaScript tutorial has 10 hands-on exercises. Estimated time: 20 minutes.
- The seven primitive types — JavaScript has seven primitive types. You have already seen a few — now let's meet them all.
- number — JavaScript does floats by default — JavaScript uses a 64-bit float for ALL numbers — integers and decimals share one type.
- string — text in JavaScript — Strings can use single quotes, double quotes, or backticks. Backtick strings (template literals) are the most powerful —…
- boolean — just two values — `true` and `false`. That's it. They control every `if` statement, every loop condition, every decision.
- null vs undefined — two 'nothing' values — JavaScript has two ways to say 'no value here', which confuses everyone:
- The coercion trap — == vs === — This is one of JavaScript's most famous footguns. `==` (loose equality) converts types before comparing — `===` (strict …
- Type conversion — be explicit — Rather than letting JS coerce types silently, convert explicitly:
- Truthy and falsy — JavaScript treats certain values as `false` in boolean contexts:
- NaN — the weird number — `NaN` means 'Not a Number' — but `typeof NaN === 'number'`. It is JavaScript's way of saying 'I tried to do math but the…
- All types in one program — Final challenge — no starter code.
JavaScript Data Types concepts covered
- Everything has a type