Skip to content

Commit 54dd6c5

Browse files
authored
Merge pull request #14 from glaubinix/t/14
Exercise 14
2 parents 0aae68b + 9c165d6 commit 54dd6c5

File tree

2 files changed

+25
-87
lines changed

2 files changed

+25
-87
lines changed

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

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

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

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +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);
14-
// age = 200;
15-
// console.log(age, age2);
16-
17-
// let name = 'Wes';
18-
// let name2 = name;
19-
// console.log(name, name2);
20-
// name = 'wesley';
21-
// console.log(name, name2);
11+
let age = 100;
12+
let age2 = age;
13+
console.log(age, age2);
14+
age = 200;
15+
console.log(age, age2);
16+
17+
let name ='wes';
18+
let name2 = name;
19+
console.log(name, name2);
20+
name = 'wesley';
21+
console.log(name, name2);
2222

2323
// Let's say we have an array
2424
const players = ['Wes', 'Sarah', 'Ryan', 'Poppy'];
2525

2626
// and we want to make a copy of it.
2727
const team = players;
28-
2928
console.log(players, team);
29+
3030
// You might think we can just do something like this:
31-
// team[3] = 'Lux';
31+
// team[3] = 'Lux';
3232

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

@@ -48,8 +48,6 @@
4848

4949
// or use the new ES6 Spread
5050
const team4 = [...players];
51-
team4[3] = 'heeee hawww';
52-
console.log(team4);
5351

5452
const team5 = Array.from(players);
5553

@@ -59,40 +57,32 @@
5957

6058
// with Objects
6159
const person = {
62-
name: 'Wes Bos',
63-
age: 80
60+
name: 'Wes Bos',
61+
age: 80
6462
};
6563

6664
// and think we make a copy:
67-
// const captain = person;
68-
// captain.number = 99;
65+
const captain = person;
66+
// captain.number = 99;
6967

7068
// how do we take a copy instead?
71-
const cap2 = Object.assign({}, person, { number: 99, age: 12 });
72-
console.log(cap2);
69+
const captain2 = Object.assign({}, person, {number: 99});
7370

7471
// We will hopefully soon see the object ...spread
75-
// const cap3 = {...person};
72+
// const captain3 = {...captain};
7673

7774
// 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.
78-
7975
const wes = {
80-
name: 'Wes',
81-
age: 100,
82-
social: {
83-
twitter: '@wesbos',
84-
facebook: 'wesbos.developer'
85-
}
76+
name: 'Wes',
77+
age: 100,
78+
social: {
79+
twitter: '',
80+
facebook: ''
81+
}
8682
};
87-
8883
console.clear();
8984
console.log(wes);
90-
9185
const dev = Object.assign({}, wes);
92-
93-
const dev2 = JSON.parse(JSON.stringify(wes));
94-
95-
9686
</script>
9787

9888
</body>

0 commit comments

Comments
 (0)