Skip to content

Unclosed Template Literal

Quick summary

You opened a template literal with ` but never closed it — the parser runs to the end of the file looking for the closing backtick.

Why this happens

  • Forgot the closing backtick after a template expression

  • Nested backtick inside the template without escaping

  • Accidentally deleted the closing backtick while editing

Minimal example

✗ Broken code
const msg = `Hello ${name}; // SyntaxError: Unterminated template literal
console.log(msg);
✓ Fixed code
const name = 'Ada';
const msg = `Hello ${name}`; // closed
console.log(msg); // 'Hello Ada'

The template literal is missing its closing backtick, so the parser consumes the rest of the file as string content. Adding the closing backtick terminates it correctly.

How to diagnose

  • Read the SyntaxError — it usually reports 'Unterminated template literal'

  • Find the opening backtick and verify a matching close exists

  • Use editor syntax highlighting to spot the unbalanced backtick

How to fix

  • Add the missing closing backtick

  • Escape nested backticks with \\` inside the template

  • Use a regular string with concatenation if backticks are hard to balance

How to prevent

  • Use an editor with bracket matching that highlights backtick pairs

  • Run a linter that detects unterminated literals

Related Resources

Related Glossary

Related Lessons

  • Strings

    Learn about template literals.

← Back to language