JavaScript/Template literals
[i]Learn· Numbers and strings

Template literals

Template literals are string literals allowing embedded expressions. You can use multi-line strings and string interpolation features with them.

Template literals are enclosed by backtick (grave accent) characters (`) instead of double or single quotes. Template literals can contain placeholders. These are indicated by the dollar sign and curly braces (${expression}).

Multi-lines

Any new line characters inserted in the source are part of the template literal. Using normal strings, you would have to use the following syntax in order to get multi-line strings:

console.log(
  "string text line 1\n\
string text line 2",
);
// "string text line 1
// string text line 2"

To get the same effect with multi-line strings, you can now write:

console.log(`string text line 1
string text line 2`);
// "string text line 1
// string text line 2"

Embedded expressions

In order to embed expressions within normal strings, you would use the following syntax:

const five = 5;
const ten = 10;
console.log(
  "Fifteen is " + (five + ten) + " and not " + (2 * five + ten) + ".",
);
// "Fifteen is 15 and not 20."

Now, with template literals, you are able to make use of the syntactic sugar making substitutions like this more readable:

const five = 5;
const ten = 10;
console.log(`Fifteen is ${five + ten} and not ${2 * five + ten}.`);
// "Fifteen is 15 and not 20."

For more information, read about Template literals in the JavaScript reference.

Source: Numbers and strings by Mozilla Contributors, licensed under CC-BY-SA-2.5. Retrieved 2026-11-18. Changes: Extracted the section "Template literals"; removed the code-block language labels and the previous/next links; moved headings up one level; made links absolute; examples are the page's own code blocks, unchanged.