By Stephen Bucaro
To concatenate means to connect together. If you need to concatenate two
or more strings, you can use the String object's concat method, as shown below.
var firstString = "Now is the time for all good men ";
var secondString = "to come to the aid of their country.";
var myString = firstString.concat(secondString);
In fact you can use the concat method to connect any number of strings
together by separating the strings names with commas, using the syntax shown below.
string.concat(string1, string2, ... ,stringN)
In fact, using the concat method is not strictly necessary, as you can use the
"+" operator to concatenate strings as shown below.
var strFirst = "John";
var strLast = "Kennedy";
var strFull = strFirst + "F." + strLast;
You can use the "+" operator combined with the "=" operator to concatenate a character
or string of characters to the end of an existing string as shown below.
var strPatriot = "Now is the time for all good men ";
strPatriot += "to come to the aid of their country.";
Using this "+=" operator combination, you can concatenate groups of characters to create
very long strings, as shown below.
var strRabbit = "So Alice was considering, in her own mind, ";
strRabbit += "whether the pleasure of making a daisy-chain ";
strRabbit += "would be worth the trouble of getting up and ";
strRabbit += "picking the daisies, when suddenly a white ";
strRabbit += "rabbit with pink eyes ran close by her.";
As you can see, there are several ways to concatenate, or connect together,
stings of characters.
More Java Script Code:
• Java Script Include a Backslash Character in a String
• Java Script Math.cos Method
• The Document Object Model (DOM)
• Use Escape to Replace Dangerous Characters
• Java Script Events
• Java Script Trigonometric Methods
• The Screen Object
• Java Script prompt Message Box
• Interactively Set Webpage Colors