0%

Introduction to JavaScript III

Primitives are copied by their value.
Objects are copied by their reference(memory address)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

console.log("----primitives")
let number = 10;
function increase(number){
number++;
console.log(number); // 11

}
increase(number);
console.log(number); // 10

console.log("----references")
let obj = {value:10};
function increaseObj(obj){
obj.value++;
console.log(obj.value) // 11
}
increaseObj(obj);
console.log(obj.value); // 11

Thanks for @Mosh‘s great video tutorials.

-------------End of blogThanks for your reading-------------