Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

JavaScript Shallow Copy (spread operator)

node v14.20.1
version: 1.0.0
endpointsharetweet
const myBrowser = { language: 'JavaScript', framework: 'Angular', browser: 'Brave', os: 'Windows 11', date: { time: new Date().getTime(), date: null } } const myBrowserShallowCopy = {...myBrowser}; console.log('before myBrowser:', myBrowser); console.log('before myBrowserShallowCopy:', myBrowserShallowCopy); myBrowserShallowCopy.browser = 'Chrome'; console.log('after update shallow myBrowser:', myBrowser); console.log('after update shallow myBrowserShallowCopy:', myBrowserShallowCopy); myBrowser.date.date = new Date(); console.log('after update original myBrowser:', myBrowser); console.log('after update original myBrowserShallowCopy:', myBrowserShallowCopy);
Loading…

no comments

    sign in to comment