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);
} increase(number); console.log(number);
console.log("----references") let obj = {value:10}; function increaseObj(obj){ obj.value++; console.log(obj.value) } increaseObj(obj); console.log(obj.value);
|
Thanks for @Mosh‘s great video tutorials.