Pilcrow Records

Scripter Javascript Tutorial

javascriptmusiclogicscripterbookexcerpttutorial

26 Combining Strings

MDN: Expressions and Operators: Addition: String Concatenation

As already seen, a string is basically text. In JavaScript, it’s possible to combine strings in much the same way numbers can be added. This is useful in troubleshooting and debugging.

var text1 = "foo";
var text2 = "bar";
var text3 = text1 + text2; // foobar

When combining numbers and strings, numbers are automatically converted into strings:

var num = 1;
var str = "bar";
var text = num + str; // "1bar"