Explain the concept of mutability in the context of JavaScript primitives and objects.

Mutability refers to whether a value can be changed after it is created. In the context of JavaScript, the concept of mutability differs between primitives and objects.

1. Primitives: Immutable
   - Primitives are immutable in JavaScript. Once a primitive value is assigned to a variable, it cannot be changed. Any operation that seems to modify a primitive value actually creates a new value.
   - For example, if you have a variable with a number value, like `let x = 5;`, you cannot change the value of `x` directly. Any operation that seems to modify `x` actually creates a new value.


   let x = 5;
   x = x + 1; // Creates a new value (6), but doesn't modify the original value (5)


2. Objects: Mutable
   - Objects in JavaScript are mutable, meaning their state can be modified after creation. You can add, update, or remove properties of an object, making it flexible for dynamic changes.
   - When you modify an object, you are working with a reference to the object, and the changes affect the original object.

   let person = { name: "John", age: 25 };
   
   // Modifying the object directly (mutating)
   person.age = 26; 

   // Adding a new property (mutating)
   person.address = "123 Main St"; 


In the case of objects, mutability allows for more dynamic and flexible data structures. However, it's important to be aware of potential side effects, especially when dealing with shared references to objects.

Understanding mutability is crucial for managing state and avoiding unexpected changes in your JavaScript programs. The distinction between immutable primitives and mutable objects contributes to the predictability and stability of code.