JavaScript data types explained with typeof
primitive types, string, number, boolean, null, undefined, symbol, bigint, typeof operator, dynamic typing, type coercion basics
JavaScript's Eight Types
JavaScript is dynamically typed โ a variable can hold any type and change types at runtime. Every value belongs to one of eight types. Knowing them prevents the type coercion bugs that trip up every developer new to the language.
Primitives
Primitives are immutable values passed by value, not by reference. There are seven: string, number, boolean, null, undefined, symbol, and bigint.
typeof "hello" // "string"
typeof 42 // "number"
typeof 3.14 // "number" (no separate float type)
typeof true // "boolean"
typeof undefined // "undefined"
typeof null // "object" โ famous bug, preserved for compatibility
typeof Symbol() // "symbol"
typeof 9007199254740993n // "bigint"
Object โ Everything Else
Arrays, functions, dates, and plain objects are all of type object under the hood. Functions get a special-case result from typeof.
typeof {} // "object"
typeof [] // "object"
typeof function(){} // "function" โ special case in the spec
Dynamic Typing in Practice
Because types are determined at runtime, JavaScript will silently convert them during operations โ this is called coercion. The expression "5" + 1 returns "51" (string concatenation), not 6. Always use === instead of == to avoid implicit type conversion in comparisons. Understanding which type each value holds at any moment is the foundation of writing predictable JavaScript.
