> For the complete documentation index, see [llms.txt](https://javascript-1.gitbook.io/javascript/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://javascript-1.gitbook.io/javascript/fp/immutability.md).

# Immutability

In functional programming, the idea of immutability is not changing the state, instead taking copies of the state and returning a new state every time.

```javascript
Ex:
const obj = { name: 'Vijay' };
function clone(obj) {
    return { ...obj }; // this is pure
}
// obj.name = 'Nana'; // mutating the data
// insted mutating create function to update name
function updateName(obj) {
    const newObj = clone(obj);
    newObj.name = 'Nana';
    return newObj;
}

const updatedbj = updateName(obj);
console.log(obj, updatedbj); // { name: 'Vijay' } { name: 'Nana' } // immutability
```
