I am new to JS and was learning value and reference types in JS but I faced some confusion on the below code:
const obj = {
arr: [{
x: 17
}]
};
let z = obj.arr;
z = [{
x: 25
}];
console.log(obj.arr[0].x);
The above code outputs 17 but why? Well, arr is a reference type, that is, it is mutable then we equalize obj.arr to variable z so z holds reference to arr array in obj object. Finally, z holding 17 then we change it to 25 but it output 17.