// Each user gets a copy of the defaults. This runs fine - read the output.
// Ben never opened his settings.
const defaultSettings = {
theme: "light",
notifications: { email: true, sms: false },
};
function makeUserSettings(name) {
return { name, ...defaultSettings };
}
const ana = makeUserSettings("Ana");
const ben = makeUserSettings("Ben");
// Ana changes two of her own settings.
ana.theme = "dark";
ana.notifications.email = false;
console.log("Ben's theme:", ben.theme); // expected: light
console.log("Ben's email:", ben.notifications.email); // expected: true