prepend a string to the beginning of another string in typescript

To prepend a string to the beginning of another string in TypeScript, you can use the concatenation operator +.

index.ts
// Example string to prepend to
let myString = ' world';

// Prepend the string
myString = 'Hello' + myString;

console.log(myString); // Output: Hello world
158 chars
8 lines

Alternatively, you can use the concat() method to achieve the same result:

index.ts
// Example string to prepend to
let myString = ' world';

// Prepend the string using concat()
myString = 'Hello'.concat(myString);

console.log(myString); // Output: Hello world
179 chars
8 lines

Both methods will result in the same output: 'Hello world'.

gistlibby LogSnag