Every value in JavaScript has a type, even though you never have to declare it up front. Understanding the difference between JavaScript's primitive types and object types explains a lot of behavior that otherwise looks confusing — like why copying an array works differently from copying a number.

Primitive Types

JavaScript has seven primitive types. A primitive is immutable and copied by value, meaning assigning it to a new variable creates an independent copy.

let name = "Alex";       // string
let age = 30;             // number
let isActive = true;      // boolean
let nothing = null;       // null — intentional "no value"
let notSet;                // undefined — declared but never assigned
let id = Symbol("id");     // symbol — a unique, unforgeable value
let big = 9007199254740993n; // bigint — for integers beyond Number's safe range

console.log(typeof name, typeof age, typeof isActive);
console.log(typeof nothing, typeof notSet);

Output:

string number boolean
object undefined

Notice that typeof null returns "object" — this is a famous, decades-old bug in JavaScript that was never fixed because fixing it would break existing websites. It's worth just memorizing as a quirk.

Object Types

Everything that isn't a primitive is an object — this includes plain objects, arrays, functions, and dates. Objects are copied by reference, not by value:

let original = { score: 10 };
let copy = original;
copy.score = 99;

console.log(original.score); // changed too — both variables point to the same object

Output:

99

This reference behavior trips up a lot of beginners coming from languages where assignment always copies the value. With objects and arrays in JavaScript, assignment just copies a pointer to the same underlying data.

Checking a Value's Type

console.log(typeof "hello");     // "string"
console.log(typeof 42);           // "number"
console.log(typeof [1, 2, 3]);    // "object" — arrays are objects too!
console.log(Array.isArray([1, 2, 3])); // true — the reliable way to check for an array

Output:

string
number
object
true

typeof is useful, but since arrays, functions, and plain objects all report "object", you'll often need a more specific check like Array.isArray(). Once you're comfortable with types, the next logical step is understanding how JavaScript converts values between them, which is covered in type conversion and coercion.