35 min·beginner

Lesson 6

Strings & template literals

Build a practical mental model for strings & template literals and use it in working JavaScript.

By the end, you will be able to…

  • Explain strings & template literals in your own words
  • Use strings & template literals in a small program
  • Recognize and debug a common failure mode

Build the mental model

Template literals (backticks) let you interpolate expressions directly into strings and span multiple lines, replacing the older pattern of concatenating with +.

Syntax and working example

Read the code from inputs to output. Predict what it prints, then run it and change one value.

Working example
Expected output: Hello, Ada! You have 4 messages.

Why this matters

Interpolated templates are dramatically easier to read and less error-prone than chains of + concatenation, especially once several values are involved.

Real-world example

Every React component and server-rendered HTML template you'll eventually write leans on this exact syntax.

Common mistakes

  • Mixing quote styles and losing track of escaping
  • Forgetting the backticks (`) required for interpolation, using regular quotes instead
  • Concatenating many + operators instead of one readable template literal

Try it yourself

Challenge

Rewrite the concatenation below as a single template literal.

Practice

Knowledge check

What syntax turns a string into a template literal that can interpolate variables?

Summary

Use backtick template literals to interpolate values and build multi-line strings clearly.