Created
September 12, 2018 12:57
-
-
Save ristaa/2489e8b198748041659e3d33b987c6f2 to your computer and use it in GitHub Desktop.
Usage of 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
let firstString = `He says: "Ok, let's do that".`; // He says: "Ok, let's do that". | |
// Variable interpolation | |
let name = "Joe"; | |
let secondString = `Hi, my name is ${name}.`; // Hi, my name is Joe. | |
// Expression interpolation | |
let isMarry = true; | |
let thirdString = `Please say hello to ${isMarry ? "Marry" : "Mike"}!`; // Please say hello to Marry! | |
// Multi-line | |
let paragraph = `This is first line, | |
but this should be on second line. | |
And this on third line.`; | |
/* | |
This is first line, | |
but this should be on second line. | |
And this on third line. | |
*/ | |
// HTML templates | |
let HTMLstring = ` | |
<div> | |
<ul> | |
<li>First</li> | |
<li>Second</li> | |
<li>Third</li> | |
</ul> | |
</div> | |
`; | |
// returns HTML with unorder list and three elements |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment