Primitives Are Immutable
What you'll learn: You'll understand that primitive values in JavaScript cannot be changed—every operation creates a brand-new value instead.
What Does Immutable Mean?
When we say primitives are immutable, we mean they cannot be altered or modified after they're created. Think of a primitive value like a number written in permanent ink—you can't erase or change it. You can only create a new number.
This might seem strange at first, but it's fundamental to how JavaScript works with the seven primitive types you've learned: undefined, null, boolean, number, string, symbol, and bigint.
How This Works in Practice
When you perform an operation on a primitive, JavaScript doesn't modify the original value. Instead, it creates a completely new value:
let x = 5;
x + 3; // Creates the new value 8, but x is still 5
console.log(x); // 5
x = x + 3; // Creates 8 and assigns it to x
console.log(x); // Now x holds 8 (a different value, not a modified 5)
The number 5 itself never changed. When we wrote x = x + 3, JavaScript created the new number 8 and stored it in x. The original 5 still exists unchanged in memory.
Think of Values Like Printed Cards
Imagine primitive values as printed cards. If you have a card with "5" on it, you cannot erase the 5 and write 8. You can only create a new card with "8" printed on it and hold that one instead. The "5" card remains unchanged.
Key Takeaway: Primitive values in JavaScript are immutable—they cannot be modified. All operations create new values rather than changing existing ones.