forked from jhu-ep-coursera/fullstack-course4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
65 lines (42 loc) · 1.01 KB
/
Copy pathscript.js
File metadata and controls
65 lines (42 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copy by Reference vs by Value
var a = 7;
var b = a;
console.log("a: " + a);
console.log("b: " + b);
b = 5;
console.log("after b update:");
console.log("a: " + a);
console.log("b: " + b);
var a = { x: 7 };
var b = a;
console.log(a);
console.log(b);
b.x = 5;
console.log("after b.x update:");
console.log(a);
console.log(b);
// Pass by reference vs by value
function changePrimitive(primValue) {
console.log("in changePrimitive...");
console.log("before:");
console.log(primValue);
primValue = 5;
console.log("after:");
console.log(primValue);
}
var value = 7;
changePrimitive(value); // primValue = value
console.log("after changePrimitive, orig value:");
console.log(value);
function changeObject(objValue) {
console.log("in changeObject...");
console.log("before:");
console.log(objValue);
objValue.x = 5;
console.log("after:");
console.log(objValue);
}
value = { x: 7 };
changeObject(value); // objValue = value
console.log("after changeObject, orig value:");
console.log(value);