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 Basics (Retired) Storing and Tracking Information with Variables Review Concatenation

nathaniel marquez
seal-mask
.a{fill-rule:evenodd;}techdegree
nathaniel marquez
Full Stack JavaScript Techdegree Student 2,145 Points

Frustrated.

Im not even sure how to ask this ...

concatenation does not require a space while space does make strings and the like more readable its not required. So ...

I chose the answer with

'hello' + 'world' <--- was told this is wrong because it needs a space.

Fine ...

I chose the answer ... NONE of the above cause NONE of them have a space to the right of any of the strings. <--- was told I was wrong still ...

also ... while i was typing this message out I was apparently taking the test too, because the background kept selecting answers and typing while I was typing this message ... and amazingly I got it wrong still.

:( Frustrated.

1

2 Answers

jason chan
jason chan
31,009 Points
'hello' + ' world'

// be very careful of spaces

Yes, otherwise the response will be helloworld

brandonlind2
brandonlind2
7,823 Points

The space in a string " inside" is needed, because the space is treated like another character i think, so for example if you need to create a sentance you would need spaces,

var sent= 'this is a sentence';// this is a sentence
var sent2="thisisasentnece";//thisisasentence
var sent3="this is a" + "sentence";//this is asentence"
//spaces are required for strings
//but its not required for concatenation
//which means a space isn't required out side the string   
//outside not required " inside required" outside not required + " inside required"
//for exmple 
var string1= "this " + "is " + "a " + "string ";
//is the same as
var string2= "this "+"is "+"a "+"string";
//note it works the same and a space isnt required when concatenating, in other words a space isnt required with the + sign
// but its required inside a string
nathaniel marquez
seal-mask
.a{fill-rule:evenodd;}techdegree
nathaniel marquez
Full Stack JavaScript Techdegree Student 2,145 Points

interesting ... I was going to a tech college and I was told or advised rather that when concatenating was done the space should read from left to right ...

so it would go like ... "is required " <--- space here + "is required" <--- space not here. and doing it as tree house suggested was wrong.

I guess it was a personal preference the instructor had at the tech college.