Lesson 22 / 40

Template Literals

Build strings with template literals, expression interpolation and multi-line text.

Embedding expressions

Anything inside ${} is evaluated as a JS expression, including function calls.

const name = "Ada";
const score = 92.456;
console.log(`${name} scored ${score.toFixed(1)}%`);

Output:

Ada scored 92.5%

Multi-line strings

Line breaks inside backticks are kept as-is — no \n needed.

const msg = `Line one
Line two`;
console.log(msg);

Backticks, not quotes

Template literals use backticks, not single or double quotes — that's what enables ${} interpolation.