Template Literals

Backtick-delimited strings that support embedded expressions and multi-line text without manual concatenation.

                `text ${expression} more text`
              

Purpose

Template literals โ€” strings delimited with backticks instead of quotes โ€” let you embed any expression directly inside the string and span multiple lines without escape characters.

Syntax

const name = 'Ada';
const items = 3;

console.log(`${name} has ${items} item${items === 1 ? '' : 's'}.`);
// "Ada has 3 items."

const multiline = `Line one
Line two`;

Behavior notes

  • Anything inside ${ } is a full expression โ€” arithmetic, function calls, ternaries โ€” not just a variable name.
  • Unlike single/double-quoted strings, a literal line break inside backticks becomes part of the string, with no \n needed.
  • Nesting is allowed: a template literal can contain another template literal inside its ${ }.

Common mistakes

  • Forgetting the $ before { } โ€” {name} inside backticks is just literal text, not an interpolation.
  • Reaching for manual + concatenation out of habit when a template literal would be clearer, especially with more than one interpolated value.

Runtime notes

Part of ECMAScript since ES2015; identical behavior in every current browser and Node version.

Taught in these lessons

Related reference