Skip to content

Commit 0eb61ee

Browse files
committed
Complete Day 14 - JavaScript References VS Copying
1 parent 7a6e57e commit 0eb61ee

2 files changed

Lines changed: 19 additions & 78 deletions

File tree

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

Lines changed: 0 additions & 57 deletions
This file was deleted.

14 - JavaScript References VS Copying/index-FINISHED.html renamed to 14 - JavaScript References VS Copying/index.html

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>JS Reference VS Copy</title>
6-
<link rel="icon" href="https://fav.farm/" />
6+
<link rel="icon" href="https://fav.farm/🔥" />
77
</head>
88
<body>
99

@@ -12,24 +12,24 @@
1212
// let age = 100;
1313
// let age2 = age;
1414
// console.log(age, age2);
15-
// age = 200;
15+
// age = 200
1616
// console.log(age, age2);
1717

18-
// let name = 'Wes';
18+
// let name = 'Angela';
1919
// let name2 = name;
2020
// console.log(name, name2);
21-
// name = 'wesley';
21+
// name = 'anne';
2222
// console.log(name, name2);
2323

2424
// Let's say we have an array
25-
const players = ['Wes', 'Sarah', 'Ryan', 'Poppy'];
25+
const players = ['Angela', 'Sarah', 'Ryan', 'Poppy'];
2626

2727
// and we want to make a copy of it.
2828
const team = players;
2929

3030
console.log(players, team);
3131
// You might think we can just do something like this:
32-
// team[3] = 'Lux';
32+
//team[3] = 'Read';
3333

3434
// however what happens when we update that array?
3535

@@ -41,26 +41,26 @@
4141

4242
// So, how do we fix this? We take a copy instead!
4343
const team2 = players.slice();
44-
44+
4545
// one way
46-
46+
4747
// or create a new array and concat the old one in
48-
const team3 = [].concat(players);
48+
const team3 = [].concat(players)
4949

5050
// or use the new ES6 Spread
5151
const team4 = [...players];
5252
team4[3] = 'heeee hawww';
5353
console.log(team4);
5454

55-
const team5 = Array.from(players);
55+
const team5 = Array.from(players)
5656

5757
// now when we update it, the original one isn't changed
5858

5959
// The same thing goes for objects, let's say we have a person object
6060

6161
// with Objects
6262
const person = {
63-
name: 'Wes Bos',
63+
name: 'Angela Read',
6464
age: 80
6565
};
6666

@@ -73,26 +73,24 @@
7373
console.log(cap2);
7474

7575
// We will hopefully soon see the object ...spread
76-
// const cap3 = {...person};
76+
//const cap3 = {...person};
7777

7878
// Things to note - this is only 1 level deep - both for Arrays and Objects. lodash has a cloneDeep method, but you should think twice before using it.
7979

80-
const wes = {
81-
name: 'Wes',
80+
const angela = {
81+
name: 'angela',
8282
age: 100,
8383
social: {
84-
twitter: '@wesbos',
85-
facebook: 'wesbos.developer'
84+
twitter: '@angelaread',
85+
facebook: 'angelaread.developer'
8686
}
8787
};
8888

8989
console.clear();
90-
console.log(wes);
91-
92-
const dev = Object.assign({}, wes);
93-
94-
const dev2 = JSON.parse(JSON.stringify(wes));
90+
console.log(angela);
9591

92+
const dev = Object.assign({}, angela);
93+
const dev2 = JSON.parse(JSON.stringify(angela));
9694

9795
</script>
9896

0 commit comments

Comments
 (0)