SyntaxStudy
Sign Up
JavaScript Beginner 4 min read

Template Literals

Template Literals

Template literals use backticks and ${} for interpolation, multiline strings, and tagged templates.

Example
const name = "Alice";
const msg = `Hello, ${name}! You have ${3 + 2} messages.`;
const multiline = `Line 1
Line 2`;
// Tagged template
const html = (strings, ...vals) => strings.raw.reduce((acc, s, i) => acc + s + (vals[i] || ""), "");
Pro Tip

Tagged templates power libraries like styled-components, graphql-tag, and sql-template.