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

Why does he not open the paragraph tag and only ends it with </p> how is that possible?

In this video we are using the following code -->

message += person.skills.join(', ') + '</p>';

I am curious, why does he not open the paragraph tag? It seems like he only closes the tag with </p> like you would with any HTML code, but nowhere is the opening <p> to be found.

Thank you teamtreehouse!

2 Answers

Ryan S
Ryan S
27,275 Points

Hi Edin,

When using the addition assignment operator (+=) you can keep adding on to the value of a variable instead of replacing it. So when concatenating a long string, you can do it in pieces instead of ending up with one long line.

In this case, the opening paragraph tag was defined on the previous line and it was completed in the final line using addition assignment.

message += '<p>I have ' + person.skills.length + ' skills: ';
message += person.skills.join(', ') + '</p>';

Hope this clears things up.

Saqib Ishfaq
Saqib Ishfaq
13,912 Points

or we can use this, it works fine as well: probably just another way of using "message +="

message += '<p>I have ' + person.skills.length + ' skills: </p>'; 
message += person.skills.join(', ') ;