Template Literals in JavaScript

From the JavaScript cheat sheet · Modern JavaScript (ES6+) · verified Jul 2026

Template Literals

String templates and tagged templates

javascript
// Template literals
const name = 'John';
const greeting = \`Hello, \${name}!\`;

// Multi-line strings
const text = \`Line 1
Line 2
Line 3\`;

// Tagged templates
const styled = css\`color: red;\`;
💡 Template literals preserve whitespace and newlines
⚡ Use String.raw for paths and regex patterns
📌 Tagged templates can process and transform strings
🟢 See also: String Methods sheet for split, slice, replace, trim, and more

More JavaScript tasks

Back to the full JavaScript cheat sheet