0

Why is it that when i pass an object into the function for an argument, a reference is passed. But when i pass one of the keys in the object as an argument, it seems that a value is passed instead. I would have thought that the where 25 is stored in memory, the memory address would be passed?

Any ideas why?

let x = {name: 'Mike', age: 25};

function changeObject(x, y){
    x.name = 'Elena';
    y = 23;
    console.log(x);
};

changeObject(x, x.age);
console.log(x);

OUTPUT

{
name:"Elena",
age:25
}
{
name:"Elena",
age:25
}

0 Answers0