Tutorialspoint.dev

JavaScript | String concat()

str.concat() function is used to join two or more strings together in JavaScript.

Syntax:
str.concat(string2, string3, string4,......, stringN)

Arguments
The arguments to this function are the strings that need to be joined together. The number of arguments to this function is equal to the number of strings to be joined together.

Return value
This function returns a new string that is the combination of all the different strings passed to it as the argument.

Example for the above function is provided below:

Example 1:



print('It'.concat(' is',' a',' great',' day.'));

Output:

It is a great day.

In this example the function concat() joins together “It” with ” is”, ” a”, ” great”, “day.” to create a final string containing all the strings.

Code for the above function is provided below:

Program 1:

<script>
// JavaScript to illustrate concat() function
function func() {
  
    // Original string
    var str = 'It';
  
    // Joining the strings together
    var value = str.concat(' is',' a',' great',' day.');
    document.write(value);    
}
func();
</script> 

Output:

It is a great day.


This article is attributed to GeeksforGeeks.org

You Might Also Like

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter