Open In App

TypeScript String concat() Method

Last Updated : 11 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The concat() method in TypeScript merges two or more strings into one new string. It takes multiple string arguments and concatenates them in the order provided, returning the combined result.

Syntax

string.concat(string2, string3[, ..., stringN]); 

Parameter: This method accepts a single parameter as mentioned above and described below.

  • string2…stringN: This parameter holds the strings which will be concatenated.

Return Value: This method returns the concatenated string.

The below example illustrates the  String concat() method in TypeScriptJS:

Example 1: In this example we initializes two String objects str1 and str2, concatenates them using the concat method, converts str2 to a string explicitly, and prints the concatenated result.

JavaScript
let str1: string = "GeeksforGeeks";
let str2: string = " - Best Platform";
let result: string = str1.concat(str2);
console.log("Concatenated String:", result);

Output: 

Concatenated String: GeeksforGeeks - Best Platform

Example 2: In this example we initializes a string str1 with “GeeksforGeeks” and uses the concat method without arguments, resulting in a copy of str1. It then prints the concatenated string.

JavaScript
let str1: string = "GeeksforGeeks";
let result: string = str1.concat();
console.log("Concatenated String:", result);

Output: 

Concatenated String: GeeksforGeeks

Next Article

Similar Reads