JavaScript has 7 primitive types (string, number, bigint, boolean, undefined, null, symbol) that are immutable and passed by value, plus Object as the non-primitive reference type.
string, number, bigint, boolean, undefined, null, symbol — immutable values compared and passed by value
Objects, arrays, functions are mutable reference types — compared by reference, not value ({} === {} is false)
Returns the type as a string; typeof null is 'object' (historical bug); use === null to check for null
undefined is the engine's default for unassigned variables; null is the developer's explicit 'no value' — both are falsy
NaN !== NaN (use Number.isNaN()); BigInt cannot mix with Number without conversion; Symbol() is always unique
JavaScript is a dynamically typed language — variables don't have fixed types and can hold any value. The language has seven primitive types and one non-primitive type (Object). Understanding the distinction is fundamental to avoiding bugs and answering interview questions correctly.
string: Textual data enclosed in single quotes, double quotes, or backticks. Strings are immutable — methods like .toUpperCase() return new strings.number: 64-bit IEEE 754 floating-point. Handles both integers and decimals. Has special values: Infinity, -Infinity, and NaN (Not a Number). NaN !== NaN is true — use Number.isNaN() to check.bigint: Arbitrary-precision integers for values beyond Number.MAX_SAFE_INTEGER (2^53 - 1). Created by appending n to a literal: 123n. Cannot be mixed with regular numbers in arithmetic without explicit conversion.boolean: true or false. Used in conditionals and logical operations.undefined: Automatically assigned to variables that are declared but not initialized, and to function parameters that weren't passed.null: Intentional absence of a value. Unlike undefined, null is explicitly assigned by the developer.symbol: Unique, immutable identifiers created with Symbol(). Every Symbol() call creates a globally unique value. Used as object property keys to avoid naming collisions.'hello' === 'hello' is true.{} === {} is false because they are two different objects in memory.typeof 'hello' → 'string', typeof 42 → 'number', typeof true → 'boolean', typeof undefined → 'undefined', typeof Symbol() → 'symbol', typeof 42n → 'bigint'.typeof null → 'object' — this is a well-known bug from JavaScript's first implementation (1995) kept for backwards compatibility. Always check for null with === null.typeof function(){} → 'function' — functions are objects, but typeof gives them a special return value.typeof [] → 'object' — arrays are objects. Use Array.isArray() to check for arrays.Key Interview Distinction: null vs undefined
undefined means a variable exists but has no value assigned (the engine's default). null means a value was explicitly set to "nothing" (the developer's intent). Both are falsy. null == undefined is true (loose equality), but null === undefined is false (strict equality). Interviewers frequently test whether candidates understand this semantic difference.
Fun Fact
typeof null returning 'object' is a bug from 1995: in the original C implementation, null's type tag was 0 which matched the tag for objects — it was never fixed because too much code depended on it