Concatenation: the operation of joining two or more character strings end to end.
To join two strings together, we use the + (plus) symbol.
var name = "John" + "Doe";
This will alert "JohnDoe".
It's a little pointless to concatenate to non-variable strings together, as you could just do this:
var name = "John Doe";
Usually concatenation is used when you have variables:
var first = "John";
var last = "Doe";
var name = first + " " + last;
This will echo "John Doe";
You can also add strings to the end of a variable with "+=":
var sentence = "John Doe";
var sentence += " is so awesome!";
This will echo "John Doe is so awesome!";
[BACK to RESOURCES]