How to use Concatenation (+) In Typescript
In this approach, we are using the concatenation operator + to join strings together. The variables website and category are concatenated with the static text to create the final string stored in the message variable.
Syntax:
let result: string = string1 + string2;
Example: The below example uses Concatenation (+) to format strings in TypeScript.
Javascript
let website: string = "w3wiki" ; let category: string = "Programming" ; let message: string = "Visit " + website + " for " + category + " articles." ; console.log(message); |
Output:
"Visit w3wiki for Programming articles."
How to Format Strings in TypeScript ?
In TypeScript, the formatting of strings consists of structuring and concatenating the strings to make them in a properly readable format. We can use various approaches to format the strings in TypeScript.
There are several ways to format the string in TypeScript which are as follows:
Table of Content
- Using Concatenation (+)
- Using Template Literals
- Using eval() function
Contact Us