Home >>JavaScript String Methods >JavaScript String concat() Method
JavaScript concat() method is used to join two or more strings together. It does not change the existing string but returns a new string containing the text of the newly joined string.
Syntax:string.concat(string1, string2, ..., stringX);
Parameter | Description |
---|---|
string1, string2, ..., stringX | This is a required parameter. It defines the strings to be joined. |
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
concat() | Yes | Yes | Yes | Yes | Yes |
<html> <body> <p>Click the button to join two strings.</p> <button onclick="myFunction()">Click</button> <p id="demo"></p> <script> function myFunction() { var str1 = "PHP "; var str2 = "Python"; var res = str1.concat(str2); document.getElementById("demo").innerHTML = res; } </script> </body> </html>
Click the button to join two strings.
<html> <body> <p>Click the button to join two strings.</p> <button onclick="myFunction()">Click</button> <p id="demo"></p> <script> function myFunction() { var str1 = "PHP "; var str2 = "Python "; var str3 = "Java"; var res = str1.concat(str2,str3); document.getElementById("demo").innerHTML = res; } </script> </body> </html>
Click the button to join two strings.