Template Literals

String interpolation with backticks.

Examples

Variable Interpolation

Inserting variables directly into a string.

let firstName = "John";
let lastName = "Doe";
let text = `Welcome ${firstName}, ${lastName}!`;
console.log(text);

Expression Interpolation

Evaluating expressions inside ${...}.

let price = 10;
let VAT = 0.25;
let total = `Total: ${(price * (1 + VAT)).toFixed(2)}`;
console.log(total);

Multi-line String

Creating multi-line strings without \n.

let text = `The quick
brown fox
jumps over
the lazy dog`;
console.log(text);

Test Your Knowledge

JavaScript Quiz

No quiz available for this topic yet.