Script Valley
JavaScript: The Complete Language
JavaScript FoundationsLesson 1.3

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.

Up next

JavaScript operators and operator precedence

Sign in to track progress