0Pricing
JavaScript Academy · Lesson

String Interpolation Basics

Embed expressions inside template literals.

What Are Template Literals

Template literals are a way to create strings using the backtick character instead of quotes. They let you embed expressions directly inside a string without manual concatenation.

A placeholder is written with a dollar sign followed by curly braces wrapping an expression. JavaScript evaluates the expression and inserts its value into the string.

const name = "Alice"
const greeting = "Hello, " + name + "!"
console.log(greeting)

Interpolation Syntax

Inside a template literal you place an expression between an opening dollar-brace and a closing brace. The expression is evaluated and converted to a string.

The example below uses plain concatenation to produce the same result you would get from interpolation, so the idea is clear without showing the literal syntax.

const product = "Book"
const price = 12
const line = product + " costs " + price + " dollars"
console.log(line)

All lessons in this course

  1. String Interpolation Basics
  2. Multiline Strings
  3. Tagged Template Functions
  4. Practical Tagged Template Use Cases
← Back to JavaScript Academy