In JavaScript, mutable and immutable refer to the state of an object or value, and whether or not that state can be changed. An object or value is considered mutable if its internal state can be changed after it has been created. This means that the value can be updated or modified in-place, and any references to that value will reflect the updated state. Examples of mutable types in JavaScript include objects and arrays. On the other hand, an object or value is considered immutable if its internal state cannot be changed after it has been created. This means that the value cannot be updated or modified in-place, and any attempt to do so will result in a new value being created instead. Examples of immutable types in JavaScript include strings, numbers, and booleans. The distinction between mutable and immutable is important in functional programming, as immutable data is preferred over mutable data, since it simplifies program state management and helps to avoid bugs that can arise from unintended changes to mutable data. In JavaScript, libraries like Immutable.js provide support for immutable data structures. Here's an example to illustrate the difference between mutable and immutable objects in JavaScript:

// Mutable object (an array)
let mutableArray = [1, 2, 3];
console.log(mutableArray); // Output: [1, 2, 3]

mutableArray.push(4);
console.log(mutableArray); // Output: [1, 2, 3, 4]

// Immutable object (a string)
let immutableString = "Hello";
console.log(immutableString); // Output: "Hello"

immutableString = immutableString.concat(", world!");
console.log(immutableString); // Output: "Hello, world!"

In the example above, we first declare a mutable object mutableArray, which is an array of numbers. We can modify the contents of this array by calling its push method, which adds a new element to the end of the array. Next, we declare an immutable object immutableString, which is a string. Strings in JavaScript are immutable, so we cannot modify their contents directly. Instead, we can create a new string by using the concat method, which concatenates two strings together, and assign it to immutableString. Notice that when we modify the mutable object mutableArray, the changes are reflected in the original array. However, when we "modify" the immutable object immutableString, we actually create a new string with the desired changes, and assign it to immutableString. The original string remains unchanged. This illustrates the key difference between mutable and immutable objects in JavaScript: mutable objects can be modified in-place, while immutable objects cannot be modified in-place and instead require the creation of a new object with the desired changes.