Created
February 12, 2019 16:19
-
-
Save francisrupert/ccab4270bd4e9ebda42c3c0fe0ea5378 to your computer and use it in GitHub Desktop.
template literals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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