Having trouble understanding pass by reference and understanding the code that comes along with the lesson

Hello,
I am currently working through the lesson on pass by reference and am having trouble understanding why it works the way it does. I understand that objects and arrays are mutable because they are reference through the location in memory and not the direct value which would be the case for other primitive data tyoes…But then they start talking about obj being a variable in it’s own right and other things and it gets a little hazy…I have tried finding simpler answers and I understand the underlying principle but not really why…can someone clarify this for me?

Also, I am currently working on this exercise and this piece of code is stumping me because I don’t fully understand the syntax…

let spaceship = { crew: { captain: { name: 'Lily', degree: 'Computer Engineering', cheerTeam() { console.log('You got this!') } }, 'chief officer': { name: 'Dan', degree: 'Aerospace Engineering', agree() { console.log('I agree, captain!') } }, medic: { name: 'Clementine', degree: 'Physics', announce() { console.log(`Jets on!`) } }, translator: { name: 'Shauna', degree: 'Conservation Science', powerFuel() { console.log('The tank is full!') } } } }; // Write your code below for (let crewMember in spaceship.crew) { console.log(`${crewMember}: ${spaceship.crew[crewMember].name}`) };

In my code, I declared variable called ‘crewMember’. When I want to log it, I call ‘crewMember’ but don’t understand where it value is deriving from…how does the program know that crewMember is equal to? I use it again the next bit, but the syntax is still hazy? I need clarification…

The shapceship.crew object has 4 properties, which are the objects in it (the crewmembers);
so
let crewMember in spaceship.crew
iterates through all the properties of the spaceship.crew object.

On the first iteration of the loop, crewMember would be "captain".
On the next iteration, crewMember would be 'chief officer'.
On the next iteration, crewMember would be "medic".
On the last iteration, crewMember would be "translator".

(Assuming its iterating through the properties in this order, and these are enumerable properties.)

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.