Latest web development tutorials
 

JavaScript String concat() Method

< JavaScript String Reference

Example

Join two strings:

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

The result of res will be:

Hello world!
Try it Yourself »

More "Try it Yourself" examples below.


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

Method
concat() Yes Yes Yes Yes Yes

Syntax

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

Parameter Values

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

Technical Details

Return Value: A new String, containing the text of the combined strings
JavaScript Version: 1.2

Examples

More Examples

Example 2

Join three strings:

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

The result of res will be:

Hello world! Have a nice day!
Try it Yourself »

< JavaScript String Reference