Skip to content

Template Literal

In one line

A template literal is a string enclosed in backticks that supports multi-line text and ${expression} interpolation.

In simple words

Template literals are strings created with backticks (` ) instead of single or double quotes. They offer two features that regular strings do not: multi-line text (line breaks are preserved without \n) and expression interpolation with ${expression}`.

Interpolation evaluates any JavaScript expression inside ${} and inserts the result into the string. This is cleaner than string concatenation: `Hello, ${name}! instead of "Hello, " + name + "!"`.

Template literals can be tagged — a function can process the literal and interpolated values to create custom string formatting (e.g., for HTML escaping or internationalization).

Example

javascript
const name = "Ada";
const age = 36;
const msg = `Name: ${name}\nAge: ${age + 1}`;
console.log(msg);
// "Name: Ada\nAge: 37"

Backticks allow ${} interpolation and multi-line text.

Related terms

Related Resources

Related Lessons

Decode error messages

Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.

View errors

← Back to glossary