How to perform string interpolation in TypeScript?

JavascriptTypescriptString Interpolation

Javascript Problem Overview


C# uses string interpolation

int value = 100;
Console.WriteLine($"The size is {value}.");

Output:

>The size is 100.

How to do the same thing in TypeScript?

Javascript Solutions


Solution 1 - Javascript

In JavaScript you can use template literals:

> Template literals are literals delimited with backticks (`)

let value = 100;
console.log(`The size is ${ value }`);

Solution 2 - Javascript

Just use special `

var lyrics = 'Never gonna give you up';
var html = `<div>${lyrics}</div>`;

You can see more examples here.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionzshanabekView Question on Stackoverflow
Solution 1 - JavascriptNitzan TomerView Answer on Stackoverflow
Solution 2 - JavascriptYgalbelView Answer on Stackoverflow