Skip to content

Instantly share code, notes, and snippets.

@ristaa
Created September 12, 2018 12:57
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 ristaa/2489e8b198748041659e3d33b987c6f2 to your computer and use it in GitHub Desktop.
Save ristaa/2489e8b198748041659e3d33b987c6f2 to your computer and use it in GitHub Desktop.
Usage of template literals
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