JavaScript concat()Method
Examples
Concatenate two strings:
var str1 = "Hello ";
var str2 = "world!";
var n = str1.concat(str2);
var str2 = "world!";
var n = str1.concat(str2);
nOutput:
Hello world!
Try it Yourself »
Definition and Usage
The concat() method is used to join two or more strings.
This method does not change the original string, but returns a new string that concatenates two or more strings.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the concat() method
Syntax
string.concat(string1, string2, ..., stringX)
Parameter Values
| Parameter | Description |
|---|---|
| string1, string2, ..., stringX | Required. One or more string objects to be concatenated into a string. |
Return Value
| Type | Description |
|---|---|
| String | A new string generated after concatenating two or more strings. |
Technical Details
| JavaScript Version: | 1.2 |
|---|
More Examples
Example 2
Concatenate three strings:
var str1="Hello ";
var str2="world!";
var str3=" Have a nice day!";
var n = str1.concat(str2,str3);
var str2="world!";
var str3=" Have a nice day!";
var n = str1.concat(str2,str3);
nOutput:
Hello world! Have a nice day!
Try it Yourself »
Other Extensions
JavaScript String Object