Skip to content

Instantly share code, notes, and snippets.

@xxl007
Last active August 29, 2015 14:00
Show Gist options
  • Save xxl007/11119722 to your computer and use it in GitHub Desktop.
Save xxl007/11119722 to your computer and use it in GitHub Desktop.
Concatenating two or more strings
// Using the (+) operator (overloading)
var string1 = "This is a ";
var string2 = "test"
var string3= string1 + string2; // creates a new string with "This is a test"
// alternative using the shorthand assignment operator (+=)
var oldValue = "apples";
oldValue += " and oranges"; // string now has "apples and oranges"
// alternative using the built-in String method .concat
var nwStrng = "".concat("This ","is ","a ","string"); // returns "This is a string"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment