Basics
Data Types
Primitives (string, number, boolean, null, undefined, bigint, symbol) and Objects.
1. Explanation
JavaScript has 7 primitive types — string, number, boolean, null, undefined, bigint, symbol — and one non-primitive type: object (which includes arrays and functions). Use typeof to inspect a value's type. Primitives are immutable and compared by value; objects are compared by reference.
2. Example
Try it yourself
Console
Click Run to see output.
3. Expected output
output
string
number
boolean
undefined
object
object
object
function4. Common mistakes
- ✗Assuming typeof null returns 'null' — it returns 'object'
- ✗Using == which performs type coercion: 0 == '' is true
- ✗Mutating an object you thought was const — const only locks the binding, not the contents
5. Practice questions
- Print the typeof for: NaN, [], {}, () => {}, 1n
- Convert the string '42' into a number two different ways
- Check if a value is exactly null without confusing it with undefined