Problem
How to join together two strings and how to make one long string from numerous pieces?
Solution
For the purpose of a single statement, use the plus (+) operator to concatenate multiple strings.
var longString = "One piece " + "plus one more ";
To compose a string value in multiple statements, use the operator +=
var sentence = ""; sentence += "word1 "; sentence += "word2 "; sentence += "word3";
We can also use and the plus for this operation, but its less elegant:
var sentence = "word1 word2 word3";

Add A Comment
You must be logged in to post a comment.