File tree Expand file tree Collapse file tree 1 file changed +15
-11
lines changed
14 - JavaScript References VS Copying Expand file tree Collapse file tree 1 file changed +15
-11
lines changed Original file line number Diff line number Diff line change 8
8
9
9
< script >
10
10
// 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
16
-
17
- let name = 'Wes' ;
18
- let name2 = name ;
19
- console . log ( name , name2 ) ; //Wes Wes
20
- name = 'wesley' ;
21
- console . log ( name , name2 ) ; //wesley Wes
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
16
+
17
+ // let name = 'Wes';
18
+ // let name2 = name;
19
+ // console.log(name, name2); //Wes Wes
20
+ // name = 'wesley';
21
+ // console.log(name, name2); //wesley Wes
22
22
23
23
// Let's say we have an array
24
24
const players = [ 'Wes' , 'Sarah' , 'Ryan' , 'Poppy' ] ;
25
25
26
26
// and we want to make a copy of it.
27
+ const team = players ;
27
28
29
+ console . log ( players , team ) ;
28
30
// You might think we can just do something like this:
31
+ team [ 3 ] = 'Lux' ; //updates both team and players
32
+ //because we updated team, but team is not the array; team is just a reference to the original array, players.
29
33
30
34
// however what happens when we update that array?
31
35
You can’t perform that action at this time.
0 commit comments