Discover JavaScript's 7 primitive data types, how they are stored directly by value in stack memory, and how they differ from complex object references.
Master modern string manipulation, multi-line formatting, dynamic expression interpolation, and clean string composition using ES6 template literals.
Every piece of information in JavaScript is either a Primitive or an Object. Think of primitive data as simple, atomic values stored directly in memory (like a single number or a word), while objects are complex collections of related data stored by reference.
Understanding primitives prevents unexpected bugs when copying or comparing values. In JavaScript, primitives are immutable (their inner value cannot be changed directly) and are always copied by value. When you assign a primitive to a new variable, JavaScript creates a fresh, independent copy in memory.
JavaScript features exactly 7 primitive types:
number: Whole numbers and decimals like 42, 3.14, and special values like NaN (Not-a-Number).string: Text enclosed in quotes like "Hello World" or 'JavaScript'.boolean: Logical states: true or false.undefined: Memory space allocated by the engine, but no value assigned yet.null: Intentional assignment representing "no value" or an empty object pointer.symbol: Unique, immutable identifier created via Symbol("id").bigint: Arbitrary precision integers for handling numbers larger than 2^53 - 1 (e.g. 9007199254740991n).You can check any value's type using the built-in typeof operator:
const score = 100;
console.log(typeof score); // "number"
const name = "DevLoom";
console.log(typeof name); // "string"
const isActive = true;
console.log(typeof isActive); // "boolean"
Primitives are stored directly by value on the stack memory layout:
[ Stack Memory ]
┌──────────────┬─────────────────┐
│ Variable │ Stored Value │
├──────────────┼─────────────────┤
│ age │ 25 │
│ name │ "Alex" │
│ isOnline │ true │
└──────────────┴─────────────────┘
When you copy a primitive (let b = a), a completely new memory cell is allocated with the copied value. Mutating b has zero effect on a.
typeof null Historical Bug: An infamous quirk from JavaScript's creation in 1995 makes typeof null return "object" instead of "null". This is a legacy bug that cannot be fixed without breaking existing websites. Always check for null using strict equality: value === null.name.toUpperCase() does NOT modify the original string name. It returns a brand new string!Primitives form the raw building blocks of all JavaScript programs. Next, let's explore how variables act as labeled containers for these primitive values!