Javascript Concatenating Strings

With text strings you cannot perform mathematical operations. The most common operation performed with text strings is concatenation.Concatenation refers to the act of combining two text strings into one longer text string. For instance,the following combines the strings “ab” and “cd” into the combined string “abcd”:

“ab” + “cd”

As with numeric mathematical operations,there are two points to note about concatenation:
•You can use concatenation wherever JavaScript expects a single string value.For instance,you can assign the results of a concatenation to a variable:

var myVariable = “ab” + “cd”;

•You can use variables containing string values anywhere in your concatenation in place of actual strings. For instance, if thisVar is a variable with the value “cd ” then the results of the following JavaScript code are the same as the preceding example:
var myVariable = “ab” + thisVar;
Note :
• When you are working with strings, keep in mind that the plus sign no longer has its mathematical meaning; instead, it indicates that concatenation should be performed.


<script language="JavaScript">
var myVariable = "Hello";
var anotherVariable = "there";
var finalResults = myVariable + " " + anotherVariable;
//Use brackets if you want to add 3 and 3 before making the string.
document.write (myVariable + (3+3) + anotherVariable);
// -->