Latest web development tutorials

JavaScript concat () method

String Object Reference JavaScript String Object

Examples

Concatenate two strings:

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

n output:

Hello world!

try it"

Definition and Usage

concat () method is used to connect two or more strings.

This method does not change the original string, but returns to connect two or more of the new string.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support concat () method


grammar

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

Parameter Value

参数 描述
string1 , string2 , ..., stringX 必需。将被连接为一个字符串的一个或多个字符串对象。

return value

类型 描述
String 两个或多个字符串连接后生成的新字符串。

technical details

JavaScript version: 1.2


More examples

Example 2

3 connection string:

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

n output:

Hello world! Have a nice day!

try it"


String Object Reference JavaScript String Object