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 trialAakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsString
html += '<div style="background-color:' + rgbColor + '"></div>'; Please explain anyone , how inverted commas are used here. I think a variable can't be placed inside a string , but here "rgbColor" is used in between inverted commas.
2 Answers
andren
28,558 PointsThe example you posted does mix a lot of different single and double quotes together which makes it hard to follow but the variable is actually outside the string. The quotes surrounding it are used to end and start the strings that are on either side of it. Take a look at the code with some color highlighting:
html += '<div style="background-color:' + rgbColor + '"></div>'
The first ' single quote starts the string and then the second single quote ' ends the string. Then the rgbColor
variable is concatenated to the variable using the + operator. Then another string is concatenated which starts and ends with a single quote.
The double quotes " within the string is just treated as normal text since they hold no special meaning in a string that is started with single quotes.
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 Points<div starts with a single quote then comes a double quote, what does it mean?
Steve Gallant
14,943 PointsThe double quote is actually part of the string in this case, rather than a string delimiter. It is surrounding the value of the background-color property within the div tag.
Aakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsAakash Srivastav
Full Stack JavaScript Techdegree Student 11,638 PointsI understood little bit, but I still have that why double quote is used in '<div style="background-color:' and '"></div>'