Skip to content

Instantly share code, notes, and snippets.

@ristaa ristaa/strings.js
Created Sep 12, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.