Copy objects in JS with spread syntax

Let’s say in your code you have an object:

const object = {
    name: 'Ash',
    color: 'red',
    age: 100
};

If you want to copy that object to a new object you can do that like…

const newObject = { ...object };

If you wanted to copy that object but also update one of the values, you could do that like…

const newObject = {
    ...object,
    color: 'purple'
};