Last active
August 29, 2015 14:00
-
-
Save xxl007/11119722 to your computer and use it in GitHub Desktop.
Concatenating two or more strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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