Visitar URL original
tutorial #14 finished · mochibot/JavaScript30@e3ee54c · GitHub
Skip to content

Commit e3ee54c

Browse files
author
mochibot
committed
tutorial wesbos#14 finished
1 parent 2ef7e15 commit e3ee54c

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,27 @@
88

99
<script>
1010
// start with strings, numbers and booleans
11+
let age = 100;
12+
let age2 = age;
13+
console.log(age, age2); //100, 100
14+
age = 200;
15+
console.log(age, age2); //200, 100
1116

1217
// Let's say we have an array
1318
const players = ['Wes', 'Sarah', 'Ryan', 'Poppy'];
1419

1520
// and we want to make a copy of it.
16-
21+
const playersCopy1 = [...players];
22+
const playersCopy2 = ([]).concat(players);
23+
const playersCopy3 = players.slice();
24+
const playersCopy4 = Array.from(players);
25+
console.log(players);
26+
console.log(playersCopy1);
27+
console.log(playersCopy2);
28+
console.log(playersCopy3);
29+
console.log(playersCopy4);
1730
// You might think we can just do something like this:
18-
31+
1932
// however what happens when we update that array?
2033

2134
// now here is the problem!
@@ -43,7 +56,11 @@
4356
};
4457

4558
// and think we make a copy:
46-
59+
const personCopy1 = {...person}
60+
const personCopy2 = Object.assign({}, person)
61+
console.log(person);
62+
console.log(personCopy1)
63+
console.log(personCopy2)
4764
// how do we take a copy instead?
4865

4966
// We will hopefully soon see the object ...spread

0 commit comments

Comments
 (0)