append a string to the end of another string in typescript

To append a string to the end of another string in TypeScript, you can use the concatenation operator + or the concat() method.

Using + operator:

index.ts
let str1: string = "Hello, ";
let str2: string = "World!";
let result: string = str1 + str2;
console.log(result); // Output: "Hello, World!"
141 chars
5 lines

Using concat() method:

index.ts
let str1: string = "Hello, ";
let str2: string = "World!";
let result: string = str1.concat(str2);
console.log(result); // Output: "Hello, World!"
147 chars
5 lines

In both cases, the output will be the same concatenated string of str1 and str2, which is "Hello, World!".

gistlibby LogSnag