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 trialAlex Sanchez
4,501 Pointsstring+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
28,558 PointsQuotes 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".
Henrik Christensen
Python Web Development Techdegree Student 38,322 Pointsvar name = "Dave";
var message = "Hello " + name; // here you are refering the variable name and therefor does not need quotation marks
Alex Sanchez
4,501 PointsThank you!!
Paul Walker
28,904 PointsThe name is a variable so it does not need any quotation marks around it. the "Hello " is a string so it needs quotation marks.
Alex Sanchez
4,501 PointsAlex Sanchez
4,501 PointsThank you!!