Multi-Line JavaScript Strings

The JavaScript language automatically adds semicolons to the end of lines, so creating multi-line strings like this will fail and generally result in errors…

Bad Multi-line String Example

Concationation Multi-line String Example
Below is one correct method to do it that uses concatenation…

Array to Multi-line String Example
Below is another method I recently saw used for multi-line strings in JavaScript that uses an Array and the join() method…

Slash Concatenation Multi-line String Example
Below is another method that is done by adding a backslash at the end of each line which tells the JavaScript engine that the string will continue to the next line, thus avoiding the automatic semicolon insertion annoyance…

Performance Tests
Someone tested these methods along with a few other similar methods of doing Multi-line strings and the performance between each method. You can see the results here along with the code that was tested http://jsperf.com/zp-string-concatenation/6. It seems the Slash Concatenation method is the best performance wise however I personally prefer the Array + Join method shown above for my own use.