Copying an object with the spread operator only copies the top level. The nested objects are still shared, which is how bugs get in.
const copy = structuredClone(original);
copy.settings.theme = 'dark'; // original stays untouched
It is built into modern browsers and into Node.js 17 and newer. It also handles things that the old JSON.parse(JSON.stringify(x)) trick ruins, such as dates, maps, sets and nested arrays. A Date stays a Date and is not turned into a string.
Caveat: functions cannot be cloned. If the object contains one, structuredClone throws a DataCloneError. Class instances come out as plain objects without their methods.
Further reading: MDN: structuredClone