Data Types & Primitives
The building blocks of JavaScript. Learn the seven primitive types and the one reference type that governs everything else.
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
Check yourself
Pick an answer to lock it in, then read why. Getting one wrong is part of how it sticks.
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 nullfamously evaluates to'object'due to an ancient bug.
Done with this concept?
Mark it complete to track your progress. No login needed.