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

Oğulcan Girginc
Oğulcan Girginc
24,848 Points

Why not using '<p>' and '</p>' results same as using both?

Both

person.name = 'Rainbow Dash';
message += 'But, I wish my name was ' + person.name + '.';

and

person.name = 'Rainbow Dash';
message += '<p>But, I wish my name was ' + person.name + '.</p>';

results in same outcome: But, I wish my name was Rainbow Dash. Wasn't I suppose to get an error, when paragraph tags are not included?

1 Answer

Nejc Vukovic
seal-mask
.a{fill-rule:evenodd;}techdegree
Nejc Vukovic
Full Stack JavaScript Techdegree Student 36,271 Points

Hi.

No if you look at that this way then that's no error. There is no syntax error or any other error present in the code.

You can use either. But if you don't use the paragraph tags then the text will be a text without styling rules for a paragraph.

To see the difference make a new Workspace and write a basic HTML backbone and input your coding and make sure you have some text before the js code and some after.

The difference is that when using the tag you get the style for the tag applied to the HTML ( the browser defaults ) and if you don't use the tags nothing is applied but still renders in your browser.

Oğulcan Girginc
Oğulcan Girginc
24,848 Points

That's what I thought, but wasn't sure. Thanks a lot Nejc! :)