Home »
JavaScript
String concat() Method with Example in JavaScript
JavaScript String concat() Method: Here, we are going to learn about the concat() method in JavaScript with example.
Submitted by IncludeHelp, on February 07, 2019
String concat() Method
concat() is a string method in JavaScript, it is used to concatenate (join) two or more strings and returns a new joined string.
Syntax
String.concat(string1, string2, ...);
Parameters
It accepts string(s) and returns new string (which is joined string with the main string).
Sample Input/Output
Input:
str1 = "IncludeHelp"
str2 = ".com"
Function call: str1.contact(str2);
Output:
"IncludeHelp.com"
Input:
str1 = "Hello"
str2 = " " //space
str3 = "World!"
Function call: str1.contact(str2, str2);
Output:
"Hello World!"
Example
<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
var str1 = "IncludeHelp";
var str2 = ".com";
document.write(str1.concat(str2) + "<br>");
str1 = "Hello";
str2 = " ";
var str3 = "World!";
document.write(str1.concat(str2, str3) + "<br>");
</script>
</body>
</html>
Output
IncludeHelp.com
Hello World!
JavaScript String Object Methods »