JavaScript tutorial:
concat Method (String)

 

Applies to: Array Object, String Object

The concat method returns a String object containing the concatenation of two supplied strings.

Syntax

string1.concat(string2)

The concat method syntax has these parts:

Part

Description

string1

Required. The String object or literal to concatenate with string2.

string2

Required. A String object or literal to concatenate to the end of string1.

Return value

The concat method returns the result of two concatenated string.

Example

The result of the concat method is equivalent to: result = string1 + string2.

The following example illustrates the use of the concat method:
function concatString (str1, str2)
{
var s = str1.concat(str2);
// Return concatenated string.
return(s);
}
document.write(concatString("Hello World ","Java Script is fun"));

To run the code, paste it into JavaScript Editor, and click the Execute button.

See also: Addition Operator (+), concat Method (Array), String Object Methods