JavaScript Template literals

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

Template literals use backticks (`). Embed expressions with ${...}. They may span multiple lines without \n escapes.

JavaScript Syntax

JavaScript
const name = "Ada";
console.log(`Hello, ${name}!`);
console.log(`line1
line2`);
Try it Editor

How It Works

  1. Interpolation. ${name} inserts the value.
  2. Multi-line. Newlines inside backticks are kept.

Examples

Example 1 — Expressions inside

Any expression works.

JavaScript
console.log(`2+3=${2 + 3}`);
Try it Editor

How It Works

  1. The expression is evaluated, then stringified.

Example 2 — Nested templates

Possible but keep readable.

JavaScript
const x = 1;
console.log(`value=${`<${x}>`}`);
Try it Editor

How It Works

  1. Inner template runs first.

Example 3 — String.raw

Raw escapes.

JavaScript
console.log(String.raw`C:\new`);
Try it Editor

How It Works

  1. Backslashes stay literal.

Frequently Asked Questions

Yes. Single and double quotes need no escaping inside backticks.
A tag function can parse the template parts—advanced, used by libraries.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful