🧭Immutability
Also known as Immutable, Immutable Data
Data that cannot change once made. To change it, you make a new copy.
Think of it like
Think of it like a printed photo. To change it, you print a new one and keep the old.
Example
Jack freezes a point with x set to 1. A later line tries to set x to 5, and x is still 1.
Why it matters
Data that never changes cannot be broken by code far away.
Definition
Example code
javascript
const point = Object.freeze({ x: 1 });
point.x = 5;
console.log(point.x); // 1Common mistake
Key takeaways
- 1Fixed once made. No edits in place.
- 2New copy instead. The old one stays.
- 3Safe to share. Nobody can change it.