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.
Concatenation of single Quotes inside Double Quotes
Could Some one Explain to me how this concatenation works it is very confusing
<div> <img src="img/' + planet.name + '.jpg" alt="' + planet.name + '">' + </div>
Steven Parker220,476 Points
I would not expect that to "work". For one thing, it's incomplete. There's no statement there, only what looks like part of a concatenated string. Also, the single quotes are unbalanced — there's an odd number of them.
But it looks like the idea was to enclose the string bits in single quotes, and some of those bits have double quotes inside them. For example, in this complete statement with a modified version of this string, you can clearly see by the syntax coloring which parts are literal strings:
var sample = '<div><img src="img/' + planet.name + '.jpg" alt="' + planet.name + '"></div>';