String concat() Method - Javascript String

Javascript examples for String:concat

Description

The concat() method is used to join two or more strings.

Parameter Values

Parameter Description
string1, string2, ..., stringX Required. The strings to be joined

Return Value:

A new String, containing the text of the combined strings

The following code shows how to Join two strings:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from   w  w  w .  j  a  va2 s.c  om
    var str1 = "Hello ";
    var str2 = "world!";
    var str3 = " Have a nice day!";
    var res = str1.concat(str2, str3);
    document.getElementById("demo").innerHTML = res;
}
</script>

</body>

</html>

Related Tutorials