Primitive Values

JavaScript has seven primitive data types: string, number, bigint, boolean, undefined, symbol, and null. Primitives are immutable values. Objects, functions, arrays, dates, maps, sets, and other compound structures are objects.

number uses IEEE 754 double-precision floating-point representation, which means integers and fractional values share the same type. bigint exists for integers outside the safe integer range of number.

Inspecting Primitive Types
console.log(typeof 'hello');
console.log(typeof 42);
console.log(typeof 42n);
console.log(typeof true);
console.log(typeof undefined);
console.log(typeof Symbol('id'));
console.log(typeof null);
💡 Most typeof results match the conceptual type. The famous exception is typeof null, which returns "object" for historical compatibility.
Key Takeaways
  • Primitive values are immutable.
  • BigInt is intended for arbitrary-size integers.
  • typeof null returning object is a historical language quirk.
Knowledge Check

How many primitive data types does modern JavaScript define?