Skip to content

Instantly share code, notes, and snippets.

@francisrupert
Created February 12, 2019 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francisrupert/ccab4270bd4e9ebda42c3c0fe0ea5378 to your computer and use it in GitHub Desktop.
Save francisrupert/ccab4270bd4e9ebda42c3c0fe0ea5378 to your computer and use it in GitHub Desktop.
template literals
// The plain old way:
'<div class="' + className + '">' +
'<p>' + content + '</p>' +
'<a href="' + link + '">Let\'s go</a>'
'</div>';
// With ECMAScript 6:
`
<div class="${className}">
<p>${content}</p>
<a href="${link}">Let's go</a>
</div>
`
/*
Your string can span multiple lines.
You don't have to escape quotation characters.
You can avoid groupings like: '">'
You don't have to use the plus operato
*/
let nuts = 7
more.innerHTML = `
<h2>You collected ${nuts} nuts so far!
<hr>
Double it, get ${nuts + nuts} nuts!!
`
<div id="more"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment