Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
210,475 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. :-)