concat()  String  instance method getterS2C Home  « Globals « String « concat()

Description

Returns a new string from the concatenation of two or more strings, leaving original strings unaffected.

  • Any modifications to the new string have no affect on the strings it was created from.
  • Any modifications to the old strings have no affect on the new string created from them.

Syntax

Signature Description
aString.concat(string1, string2[, ..., stringN])Returns a new string from the concatenation of two or more strings, leaving original strings unaffected.

Parameters

Parameter Description
string1, string2[, ..., stringNStrings to concatenate into a new string.
  • Out of range indexes return an empty string.

Examples

The code below creates two new strings and concatenates a third string with the other two.


// Create 2 string varibles.
var string1 = 'Mon,Tues,Wed,Thurs';
var string2 = 'Fri,Sat,Sun';
/*
 string1 still holds value 'Mon,Tues,Wed,Thurs' after concat.
 The alert just shows the returned concat result which is
 'Mon,Tues,Wed,Thurs,Fri,Sat,Sun'.
 */
alert(string1.concat(',', string2));

Press the button below to action the above code:


Related Tutorials

JavaScript Basic Tutorials - Lesson 8 - Strings

go to home page Homepage go to top of page Top