MDN self-hosted library · e01.org

Template literals (Template strings)

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
`\`` === "`"; // true
js
`\${1}` === "${1}"; // true
js
console.log("string text line 1\nstring text line 2");
// "string text line 1
// string text line 2"
js
console.log(`string text line 1
string text line 2`);
// "string text line 1
// string text line 2"
js
console.log(`string text line 1 \
string text line 2`);
// "string text line 1 string text line 2"
js
const a = 5;
const b = 10;
console.log("Fifteen is " + (a + b) + " and\nnot " + (2 * a + b) + ".");
// "Fifteen is 15 and
// not 20."
js
const a = 5;
const b = 10;
console.log(`Fifteen is ${a + b} and
not ${2 * a + b}.`);
// "Fifteen is 15 and
// not 20."