What is immutability?

Immutability is when something stays exactly the same no matter what happens around it.

Imagine you have a super strong cookie that never breaks or changes shape, even if you drop it, squish it, or throw it at a wall. That’s like being immutable. Once it's made, it doesn’t change.

Like a Favorite Toy

Think of your favorite toy, maybe a teddy bear that you always carry with you. No matter how many times you play with it, throw it on the floor, or even take it to school, it still looks just like it did when you first got it. That's immutability in action!

Now imagine if your teddy bear changed colors every time you dropped it, that would be mutable. But since it stays the same, it’s immutable, and that makes it extra special.

Why It Matters

When something is immutable, we know exactly what to expect from it. That helps us feel safe and confident, just like knowing your favorite toy will always be there for you, no matter what!

Take the quiz →

Examples

  1. A number that never changes, like the number of sides on a square
  2. A toy that you can't break or reshape once it's made
  3. Your favorite color, it stays the same even if you see other colors

Ask a question

See also

Discussion

Recent activity