What Are Data Types?
Data types tell JavaScript what kind of value you're working with. Different types allow different operations — you can add numbers, but you can't multiply text.
Primitive Data Types
JavaScript has 7 primitive data types (plus objects). Here are the ones you'll use constantly:
1. String — Text
Text wrapped in quotes. Use single quotes, double quotes, or backticks.
"Hello world"
'JavaScript'
`Template literals`
2. Number — Any Number
No separate type for decimals — everything is a Number.
42
3.14
-5
1_000_000 // readable with underscores
3. Boolean — True or False
Only two possible values: true or false.
let isLoggedIn = true;
let isGreater = 10 > 5; // true
4. undefined — No Value Assigned
A variable that has been declared but not given a value.
let something; // undefined
5. null — Intentional Empty Value
You explicitly set this to represent "no value."
let user = null; // intentionally empty
6. Symbol — Unique Identifier
Creates a unique, immutable value. Used for object property keys.
💡 Key difference
undefined means "no value assigned yet" while null means "I'm intentionally setting this to nothing."
The typeof Operator
Use typeof to check what type a value is:
typeof "hello" // "string"
typeof 42 // "number"
typeof true // "boolean"
typeof undefined // "undefined"
typeof null // "object" (this is a historical bug in JavaScript)
⚠️ JavaScript quirk
typeof null returns "object" — this is a long-standing bug that can't be fixed without breaking existing code. Check for null explicitly.
Common Mistakes
- Confusing
undefinedwithnull— they are not the same - Using
==instead of===(we'll cover this in the Operators lesson) - Forgetting that
typeof null === "object" - Not wrapping strings in quotes
Quick Quiz
1. What is the result of typeof "Hello"?
2. Which value represents "no value assigned yet"?
3. What is the result of typeof null?
Summary
- Strings hold text, Numbers hold numeric values, Booleans hold true/false
undefinedmeans "no value assigned"nullmeans "intentionally empty"- Use
typeofto check a value's type typeof null === "object"is a known JavaScript quirk
