Template Literal (JavaScript)

A template literal is a string written with backticks that lets you embed variables and expressions using ${ }. It also allows multi-line strings.

JavaScript

Instead of joining strings with +, you write the string in backticks and drop values inside ${ }. This makes building messages much cleaner.

Template literals can span multiple lines without any special escape characters.

Syntax

`text ${expression} more text`

Examples

JavaScript

const name = "Mia";
const age = 9;
console.log(`${name} is ${age} years old`);

Output:

Mia is 9 years old

See also

Back to the Dictionary