• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

1. Strings > 1.1. Concatenating (Joining) Strings

Concatenating (Joining) Strings

NN 2, IE 3

Problem

You want to join together two strings or accumulate one long string from numerous sequential pieces.

Solution

Within a single statement, use the plus (+) operator to concatenate multiple string values:

var longString = "One piece " + "plus one more piece.";

To accumulate a string value across multiple statements, use the add-by-value (+=) operator:

var result = "";
result += "My name is " + document.myForm.myName.value;
result += " and my age is " + document.myForm.myAge.value;

The add-by-value operator is fully backward-compatible and is more compact than the less elegant approach:

result = result + "My name is " + document.myForm.myName.value;

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint