Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects Accessing Object Properties

Understand passing of objects to variables question?

Hi, When passing a variable, to a function. (message), the passing variable would contain all of the 'message' additions (+=), as well as the updates from calling the object 'person'? (person.name) ?

Is this the case?

Thanks.

Scott

2 Answers

Steven Parker
Steven Parker
228,978 Points

If I understand you correctly, the answer would be "yes".

For example, if you build up a string named message, and then pass it to a function, it will include everything that was previously added to that string.

The answer would also be "yes" if you are asking about passing the object itself and accessing the properties in it. For example, if you were to pass the object in person to a function, the function would then have access to the properties in that object, like this:

function printName(obj) {
    var message = "Hello, my name is " + obj.name;
    console.log(message);
}
printName(person);  // call the function and pass it the object in the "person" variable

Did one of those cover what you were asking?

Yes, Thank you, that is exactly what I was meaning. Helped me, understand and confirmed what I was thinking. :-)