JavaScript Template Literals and Modern Strings

JavaScript Template Literals and Modern Strings

ES6 String Formatting and Interpolation

Author
Nguyen Bao Huy
11:29:00 21/02/2026
1 min read
0 comments

Back-Tics Syntax

Template Strings use back-ticks (``) rather than the quotes ("") to define a string:

javascript
let text = `Hello World!`;

Quotes Inside Strings

Template Strings allow both single and double quotes inside a string:

javascript
let text = `He's often called "Johnny"`;

Multiline Strings

Template Strings allow multiline strings:

javascript
let text =
`The quick
brown fox
jumps over
the lazy dog`;

Interpolation

Template Strings allow variables in strings. Template strings provide an easy way to interpolate variables in strings.

text
${...}

Variable Substitutions:

javascript
let firstName = "John";
let lastName = "Doe";

let text = `Welcome ${firstName}, ${lastName}!`;

Expression Substitution

Template Strings allow interpolation of expressions in strings:

javascript
let price = 10;
let VAT = 0.25;

let total = `Total: ${(price * (1 + VAT)).toFixed(2)}`;

HTML Templates

javascript
let header = "Template Strings";
let tags = ["template strings", "javascript", "es6"];

let html = `<h2>${header}</h2><ul>`;
for (const x of tags) {
  html += `<li>${x}</li>`;
}

html += `</ul>`;

Author avatar

Nguyen Bao Huy

Lead Fullstack & AI Solutions Engineer

Specializing in Next.js App Router, React 19, TypeScript, and modern design systems. Passionate about creating seamless user experiences.

Discussion

0

No comments yet

Be the first to share your thoughts, question a concept, or provide additional tips!

Leave a Reply

Share your insights, questions, or solutions with the developer community.

Your avatar
0 / 500 characters