JavaScript template literals use backticks (`...`) instead of single or double quotes to build dynamic and multiline strings. Introduced in ES6, they let you embed expressions directly inside ${...} placeholders without messy + concatenation.
You can place any valid JavaScript expression inside ${...}, including arithmetic, function calls, and ternary checks. JavaScript evaluates the expression first and converts the result into a string automatically.
Template literals also keep line breaks and indentation exactly as written in your source file. That makes formatting emails, SQL snippets, or log blocks much cleaner than joining lines with
.
Notice how ${...} computes discounts inline and keeps multi-line output easy to read.
const customer = "Rafi";
const subtotal = 80;
const isVip = true;
const finalTotal = isVip ? subtotal * 0.85 : subtotal;
const receipt = `Customer: ${customer}
Tier: ${isVip ? "VIP (15% off)" : "Standard"}
Amount Due: $${finalTotal.toFixed(2)}`;
console.log(receipt);
A tagged template places a function name directly before the opening backtick, such as highlight`Hello ${name}` . Libraries like styled-components and GraphQL clients use tagged templates to sanitize interpolated values or parse domain syntax safely.
${}: Writing 'Hello ${name}' prints literal ${name} text because interpolation only works inside backticks.textContent instead.Yes, an expression inside ${...} can contain another backtick template literal, though extracting a helper variable keeps code much cleaner.
Escape the character with a backslash, such as \` for a backtick or \${x} to print ${x} as plain text.
+ concatenation?No, modern JavaScript engines optimize template literals to match or beat string concatenation in speed.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.