Skip to content
AgileLogics
3 min read

Template Literals

Prerequisites: Strings

A template literal (backtick-quoted string) lets you embed any expression directly inside ${ } — the standard, modern way to build strings from variables in JavaScript.

Syntax

`Hello, ${name}!`

Example

const name = "Ada";
const message = `Hello, ${name}! You have ${3 + 2} new messages.`;
console.log(message);

Expected output

Hello, Ada! You have 5 new messages.

Template literals also support multi-line text without special escape characters, unlike regular quoted strings.

Common mistakes

  • Using regular quotes ("Hello, ${name}") — ${ } interpolation only works inside backticks; with regular quotes it prints the literal text ${name}.