Data Types & Primitives

The building blocks of JavaScript. Learn the seven primitive types and the one reference type that governs everything else.

JavaScript6 min readConcept 3 of 62

What are data types?

JavaScript has two main categories of data: Primitives and Objects (Reference types).

There are seven primitive types: string, number, bigint, boolean, undefined, symbol, and null.

Everything else (arrays, functions, dates, etc.) is structurally an object.

Why does it matter?

Primitives are immutable - they cannot be changed once created. If you reassign a primitive variable, you are pointing it to a completely new value in memory.

Objects are mutable and passed by reference. Understanding this distinction is the key to preventing unexpected side effects when passing data between functions.

How it works

You can use the typeof operator to check the type of a given value. It returns a string indicating the type of the unevaluated operand.

Primitives compare by value. Two strings containing 'hello' are strictly equal ('hello' === 'hello').

Objects compare by reference. Two empty objects are not equal ({} === {} is false) because they occupy different locations in memory.

Try it out

Select a value to evaluate it. Notice the difference between the actual type and the result of the typeof operator.

Type Evaluator

Select a value

const value = 42;
console.log( typeof value );
Console Output
Primitive
"number"
iThis is one of the 7 Primitive data types in JavaScript. It is immutable and passed by value.

Check yourself

Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.

  1. 1What does `typeof null` return?
  2. 2Which of the following is NOT a primitive data type?
  3. 3What is the result of `"foo" === "foo"` compared to `{} === {}`?

Remember this

  • JavaScript has 7 primitives: string, number, bigint, boolean, undefined, symbol, null.
  • Primitives are passed by value and are immutable.
  • Objects (including Arrays and Functions) are passed by reference and are mutable.
  • typeof null famously evaluates to 'object' due to an ancient bug.

Done with this concept?

Mark it complete to track your progress. No login needed.