Skip to content

Commit dbadbea

Browse files
committed
finished Day 14
1 parent 7cef036 commit dbadbea

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

14 - JavaScript References VS Copying/index-START.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
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

@@ -25,6 +28,8 @@
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

@@ -45,6 +50,7 @@
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

0 commit comments

Comments
 (0)