Data Types
JavaScript has 9 data types. Understanding them is fundamental to writing correct code.
Primitive Types
| Type | Example | Description |
|---|---|---|
string | 'hello' | Text |
number | 42, 3.14 | Numbers (integer & float) |
bigInt | 9007199254740991n | Very large integers |
boolean | true, false | Logical true/false |
symbol | Symbol('id') | Unique identifier |
null | null | Intentional absence of value |
undefined | undefined | Value not yet assigned |
Complex Types
| Type | Example | Description |
|---|---|---|
object | { name: 'Alice' } | Collection of key-value pairs |
function | function() {} | Callable block of code |
typeof Operator
typeof 'hello' // 'string'
typeof 42 // 'number'
typeof true // 'boolean'
typeof undefined // 'undefined'
typeof null // 'object' ← famous JS quirk!
typeof {} // 'object'
typeof function(){} // 'function'
ℹ️ typeof null
typeof null returns 'object' — this is a well-known bug in JavaScript that was never fixed to maintain backwards compatibility.