Search w3schools.com:

SHARE THIS PAGE

JavaScript concat() Method

String Object Reference JavaScript String Object

Example

Join two strings:

var str1 = "Hello ";
var str2 = "world!";
var n = str1.concat(str2);

The result of n will be:

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 existing strings, but returns a new string containing the text of the joined strings.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The concat() method is supported in all major browsers.


Syntax

string.concat(string1, string2, ..., stringX)

Parameter Values

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

Return Value

Type Description
String A new string, containg the text of the combined strings

Technical Details

JavaScript Version: 1.2


More Examples

Example 2

Join three strings:

var str1="Hello ";
var str2="world!";
var str3=" Have a nice day!";
var n = str1.concat(str2,str3);

The result of n will be:

Hello world! Have a nice day!

Try it yourself »


String Object Reference JavaScript String Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]