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.
- string2…stringN: This parameter holds the strings which will be concatenate.
Return Value: This method returns the concatenated string.
Below example illustrate the String concat() method in TypeScriptJS:
Example 1:
JavaScript
<script>
var str1 = new String( 'GeeksforGeeks' );
var str2 = new String( ' - Best Platform' );
console.log( "Concatenated String : "
+ str1.concat(str2.toString()));
</script>
|
Output:
Concatenated String : GeeksforGeeks - Best Platform
Example 2:
JavaScript
<script>
var str1 = new String( 'Geeks' );
var str2 = new String( 'for' );
var str3 = new String( 'Geeks' );
var str = str2.concat(str3.toString())
str = str1.concat(str.toString())
console.log( "Concatenated String : " + str);
</script>
|
Output:
Concatenated String : GeeksforGeeks