pass by value and pass by reference in javascript
* Pass By Value:
->In Pass by value, parameters passed as an arguments create its own copy.
So any changes made inside the function is made to the copied value not to
the original value .
let a=5;
b=a;
b=a+5;
console.log(a) //output: 5
console.log(b) //output: 10
* Pass By Reference :
-> In JavaScript array and Object follows pass by reference property.
-> In Pass by reference, parameters passed as an arguments does not create its own copy, it refers to the original value so changes made inside function affect the original value.
const obj1 = {name:"abc",age:23};
const obj2 = obj1;
obj2.name="xyz";
console.log(obj2.name) //output: xyz
console.log(obj1.name) //output: xyz