Data Types

JavaScript has 9 data types. Understanding them is fundamental to writing correct code.

Primitive Types

TypeExampleDescription
string'hello'Text
number42, 3.14Numbers (integer & float)
bigInt9007199254740991nVery large integers
booleantrue, falseLogical true/false
symbolSymbol('id')Unique identifier
nullnullIntentional absence of value
undefinedundefinedValue not yet assigned

Complex Types

TypeExampleDescription
object{ name: 'Alice' }Collection of key-value pairs
functionfunction() {}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.