A.3. Template literals

String literals can now contain embedded expressions. This feature is known as string interpolation. In ES5, you’d use concatenation to create a string that contains string literals combined with the values of variables:

const customerName = "John Smith";
console.log("Hello" + customerName);

Now you can use template literals, which are strings surrounded with backtick symbols. You can embed expressions right inside the literal by placing them between the curly braces prefixed with a dollar sign. In the next code snippet, the value of the customerName variable is embedded in the string literal:

const customerName = "John Smith"; console.log(`Hello ${customerName}`); function getCustomer() { return "Allan Lou"; } console.log(`Hello ...

Get TypeScript Quickly now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.