Open In App

TypeScript | String concat() Method

The concat() is an inbuilt function in TypeScript which is used to add two or more strings and returns a new single string. 

Syntax:



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

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

Return Value: This method returns the concatenated string.



Below example illustrate the  String concat() method in TypeScriptJS:

Example 1: 




<script>
    // Original strings
    var str1 = new String('GeeksforGeeks'); 
    var str2 = new String(' - Best Platform'); 
  
    // Combines the text of two strings and 
    // returns a new string.
    console.log("Concatenated String : " 
            + str1.concat(str2.toString()));
</script>

Output: 

Concatenated String : GeeksforGeeks - Best Platform

Example 2: 




<script>
    // Original strings
    var str1 = new String('Geeks'); 
    var str2 = new String('for'); 
    var str3 = new String('Geeks'); 
  
    // Combines the text of two strings and 
    // returns a new string.
    var str = str2.concat(str3.toString())
    str = str1.concat(str.toString())
    console.log("Concatenated String : " + str);
</script>

Output: 

Concatenated String : GeeksforGeeks

Article Tags :