Combining Strings (String Concatenation)

By: Dusty Arlia
Published on August 28, 2012
Last Updated on Monday, July 06, 2015 at 12:51 PM
Total Updates: 5

Combining strings is a frequent task when writing JavaScript. This is actually called string concatenation. The concatenation operator (+) is used to perform this operation.

When the JavaScript interpreter looks at each expression on either side of the + operator, it creates a single string if either expression is already a string. Here's an example of string concatenation:

var firstName = "Dusty";
var lastName = "Arlia";
var fullName = firstName + " " + lastName;

In this example, the fullName variable gets assigned the value Dusty Arlia. The " " is a string literal that creates the space in between Dusty and Arlia.

Comments:

Ad:

Ad: