File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed
14 - JavaScript References VS Copying Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change 1313 const players = [ 'Wes' , 'Sarah' , 'Ryan' , 'Poppy' ] ;
1414
1515 // and we want to make a copy of it.
16+ // const team = players;
17+
18+ // console.log(players, team);
1619
1720 // You might think we can just do something like this:
1821
2528 // Why? It's because that is an array reference, not an array copy. They both point to the same array!
2629
2730 // So, how do we fix this? We take a copy instead!
31+ const team2 = players . slice ( ) ;
32+ team2 [ 3 ] = 'Lux' ;
2833
2934 // one way
3035
4550 // and think we make a copy:
4651
4752 // how do we take a copy instead?
53+ const person2 = Object . assign ( { } , person , { number : 22 } ) ;
4854
4955 // We will hopefully soon see the object ...spread
5056
You can’t perform that action at this time.
0 commit comments