JS & HTML quotes: an example

I’d like to understand how the quotes work on the right hand side of the new content variables. With just one line I’ll be fine, I added the rest for context.

indent preformatted text by 4 spaces

var newContent = '';
for (var i = 0; i < responseObject.events.length; i++) { // Loop through object
  newContent += '<div class="event">';
  newContent += '<img src="' + responseObject.events[i].map + '" ';
  newContent += 'alt="' + responseObject.events[i].location + '" />';
  newContent += '<p><b>' + responseObject.events[i].location + '</b><br>';
  newContent += responseObject.events[i].date + '</p>';
  newContent += '</div>';
}`indent preformatted text by 4 spaces`

Thanks.

Your question isn’t very clear, but the single quotes wrap around the HTML you want output, and in some cases that includes a closing " to complete the img src attribute, for example.

Strings in javascript can be created with single quotes or double quotes.

a = "yep";
b = 'yep';

You can safely use the other type of quote in either.

a = "yep ' works";
b = 'yep " works';

If you need to use the same type of quote in the string you’ll need to escape.

a = "yep \" works";
b = 'yep \' works';