How to Perform String Interpolation in Typescript?

How to Perform String Interpolation in Typescript?

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?

7

2 Answers

In JavaScript you can use template literals:

Template literals are literals delimited with backticks (`)

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

Just use special `

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

You can see more examples here.

6

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne
Author

Robert Thorne

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.