Pass by value
Copy
is made in memory
.
New memory allocation is done.
let num1 = 70; let num2 = num1; console.log(num1) // 70 console.log(num2) // 70 num1 = 40 console.log(num1) // 40 console.log(num2) // 70
Pass by reference
Does NOT create a new space in memory.
original memory
.const obj1 = {website: "Scaler Academy"} const obj2 = obj1; console.log(obj1); // {website: "Scaler Academy"} console.log(obj2); // {website: "Scaler Academy"} obj1.website = "Scaler Topics" console.log(obj1); // {website: "Scaler Topics"} console.log(obj2); // {website: "Scaler Topics"}