As you can see from my code sample, I am wondering why the following thing doesn't work. I have an object with an object as a property (will call it prop in the text below). When I assign the values to the prop in the function, those values are there, because obviously it is passed by reference, but I don't understand why the prop can be referenced to point to another object.
In the case of setting the prop to another object, I just get the empty object, as it is in start. What am I missing here?
const person = {
basic: {}
}
function initPersonBasics(b) {
// doesn't work
b = {
firstName: 'John',
lastName: 'Doe'
}
// works
// b.firstName = 'John';
// b.lastName = 'Doe';
}
initPersonBasics(person.basic);
console.log(person);