Data Types
Every value in JavaScript has a type, which determines what you can do with it. There are seven primitive types for simple values like text and numbers, and one structural type — the object — for everything else, including arrays and functions.
The primitive types
| Type | Examples | Used for |
|---|---|---|
| string | "hello", 'hi', `hey` | Text |
| number | 42, 3.14, -7, NaN | Integers and decimals |
| boolean | true, false | Yes/no values |
| undefined | undefined | "No value has been assigned" |
| null | null | "Deliberately empty" |
| bigint | 12345678901234567890n | Very large integers |
| symbol | Symbol("id") | Unique identifiers |
Strings, numbers and booleans are by far the most common. Lessons 13–19 cover them in depth.
Checking a type with typeof
console.log(typeof "hello"); console.log(typeof 42); console.log(typeof true); console.log(typeof undefined); console.log(typeof 10n); console.log(typeof Symbol("x"));
string number boolean undefined bigint symbol
There are two famous oddities. typeof null is "object" — a bug from the very first version of JavaScript that can never be fixed without breaking old websites. And typeof a function is "function", even though functions are technically objects:
console.log(typeof null); console.log(typeof [1, 2]); console.log(typeof function () {}); console.log(Array.isArray([1, 2]));
object object function true
To check for an array, use Array.isArray(). To check for null, compare directly: value === null.
Objects
Anything that isn't a primitive is an object — a collection of named values. Arrays, functions, dates and regular expressions are all special kinds of objects:
const person = { name: "Ava", age: 30 }; const colors = ["red", "green", "blue"]; console.log(person.name, person.age); console.log(colors[0], colors.length);
Ava 30 red 3
Lessons 29 and 36 cover arrays and objects in detail.
Dynamic typing
JavaScript is dynamically typed: a variable doesn't have a fixed type, only its current value does. The same variable can hold a number now and a string later:
let data = 42; console.log(typeof data); data = "forty-two"; console.log(typeof data);
number string
That flexibility is convenient, but it also means type mistakes only appear when the code runs. TypeScript — the subject of its own course — adds type checking on top of JavaScript to catch them earlier.
Primitives are copied, objects are shared
This difference matters constantly. Assigning a primitive copies the value; assigning an object copies a reference to the same object:
let a = 5; let b = a; b = 10; console.log(a, b); const first = { score: 5 }; const second = first; second.score = 10; console.log(first.score, second.score);
5 10 10 10
Changing b doesn't affect a, but changing second.score also changes first.score — both names point to one object. Lesson 33 shows how to make real copies with spread syntax.
Try it yourself
Predict each typeof result before running: