Template Literals
Template literals use backticks and ${} for interpolation, multiline strings, and tagged templates.
Template literals use backticks and ${} for interpolation, multiline strings, and tagged templates.
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] || ""), "");
Tagged templates power libraries like styled-components, graphql-tag, and sql-template.
More in JavaScript