Immutability

Immutability means not changing the data, not changing the state.

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.

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

Last updated