JavaScript String concat() Method

Below is the example of the concat() Method Method.

  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <script> 
    // JavaScript to illustrate concat() function 
    function func() { 
      
        // Original string 
        var str = 'Geeks'
      
        // Joining the strings together 
        var value = str.concat(' for',' Geeks'); 
        document.write(value);   
    func(); 
    </script> 

    chevron_right

    
    

  • Output:
    Geeks for Geeks
    

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<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> 

chevron_right


Output:

It is a great day.

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.