The concat() Method

To join two or more strings, use the concat() method:

   var text1 = "Hello";
   var text2 = "World";
   text3 = text1.concat(" ",text2);

HTML file: Displayed by browser:
<body>
<p>The concat() method joins two or more strings:</p>
<p id="demo"></p>
<script>
    var text1 = "Hello";
    var text2 = "World!";
    document.getElementById("demo").innerHTML = text1.concat(" ",text2);
</script>
</body>

The concat() method joins two or more strings:

The concat() method can be used instead of the plus operator. These two lines do the same:

   var text = "Hello" + " " + "World!";
   var text = "Hello".concat(" ","World!");

All string methods return a new string. They don't modify the original string. In other words, strings are immutable: they cannot be changed, only replaced.

BackTable of ContentsNext