The Kinds of Values JavaScript Knows About
JavaScript Data Types
A tour of JavaScript's data types — strings, numbers, booleans, objects, and the special ones (null, undefined, bigint, symbol).
What you'll learn
- Identify the seven primitive types and one object type
- Use `typeof` to check a value's type
- Understand that variables aren't typed — values are
Every value in JavaScript has a type. The language has eight, split into seven primitives and one object type.
| Type | Example | Notes |
|---|---|---|
string | "hello" | Text, any length |
number | 42, 3.14 | Integers and floats — same type |
boolean | true, false | Just two values |
null | null | ”Intentionally no value” |
undefined | undefined | ”No value assigned yet” |
bigint | 9007199254740993n | Whole numbers bigger than number can hold |
symbol | Symbol("id") | Unique, advanced |
object | { a: 1 }, [1, 2], function(){} | Everything else: objects, arrays, functions, dates… |
Checking a Type With typeof
The typeof operator returns a string naming the type.
console.log(typeof "hello"); // "string"
console.log(typeof 42); // "number"
console.log(typeof true); // "boolean"
console.log(typeof undefined); // "undefined"
console.log(typeof { a: 1 }); // "object"
console.log(typeof [1, 2, 3]); // "object" ← arrays are objects Dynamic Typing
JavaScript variables don’t have types — values do. The same name can hold values of different types over time.
let value = 42;
console.log(typeof value); // "number"
value = "now I'm a string";
console.log(typeof value); // "string"
value = true;
console.log(typeof value); // "boolean" This is called dynamic typing. It makes JavaScript flexible but also makes some bugs harder to catch. If you find this brittle, TypeScript adds static types on top of JavaScript.
null vs undefined
Two values for “nothing”, with subtly different intent.
undefined— the language gives you this. A variable you declared but didn’t assign, a function parameter you didn’t pass, a property that doesn’t exist.null— you give this. It says “I deliberately wanted this to be empty.”
let a;
console.log(a); // undefined — not assigned yet
let b = null;
console.log(b); // null — intentionally empty
console.log(null === undefined); // false — different values
console.log(null == undefined); // true — loose equality says yes Up Next
The next handful of lessons drill into the most-used types — strings first.
JavaScript Strings →