Immutability in JavaScript code example
Example: js immutability
const userProfile = {
username: 'Jack',
email: 'Jack@email',
socialMedia: {
twitter: '@jack',
facebook: 'jackm',
linkedIn: 'jackmay',
},
}
const newUserProfile = {
...userProfile,
email: 'JackNew@email',
socialMedia: { ...userProfile.socialMedia, twitter: '@newTwitter' },
}
// const newUserProfile = JSON.parse(JSON.stringify(userProfile))
console.log('orginal', userProfile)
console.log('new', newUserProfile)