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 Combining Strings

string+string

example var name = "Dave"; var message = "Hello " + name; second line were it says name why does it not have quotation marks? only the first one does.

3 Answers

andren
andren
28,558 Points

Quotes are used to create Strings (text). When you are referencing something that is not a string like a variable, number or any other type of value you don't use them. On the second line name refers to the variable declared on the first line.

Since name contains a string you can combine it with other strings and do anything else you would with an actual string, but a variable is never surrounded by quotes when referenced, regardless of what it contains.

If you did add quotes to the second line then name would be treated as pure text so the result would be "Hello name" instead of "Hello Dave".

Thank you!!

Thank you!!

Paul Walker
Paul Walker
28,904 Points

The name is a variable so it does not need any quotation marks around it. the "Hello " is a string so it needs quotation marks.