1 .Copy by value:
- All primitive datatypes are copied by their value
- they are:
example:1
let x=10;
let y=x;
console.log(x);//it prints 10
console.log(y);//it prints 10
example:2
let x=10;
let y=x;
x=20;
console.log(x);//it prints 20 console.log(y);//it prints 10
3.they are INDEPENDENT of each other
2.Copy by reference:
- objects are coppied by their Reference
- they are:
example:
let x={num:10};
let y=x;
x.num=50; //or y.num=50;
console.log(x.num);
//it prints 50
console.log(y.num);
//it prints 50
3. when we modify the object in (x OR y) .that changes are immediately reflect to another variable also.