JavaScript Tips
XML Menu Builder
Build powerful, client-side DHTML menus using XML for data and CSS for style. No JavaScript data! No having to place list elements on every single page of your website! No plug-ins!

Extending a String Across Multiple Lines

In JavaScript, String Literals start and end with a quote character. String Literals cannot span multiple lines unless an escape character \ is placed at the end of each line that does not contain the ending quote character. For example, this isn't valid syntax:

var stringVar = "I am a string that
extends
beyond a single line";

The string below is valid because the escape character is appended to the end of each line of the String Literal that doesn't receive the final quote.

var stringVar = "I am a string that \
extends \
beyond a single line";

Note that had we wanted the string to appear with line terminators as it does in the source code, we would need to replace the white space characters preceding the escape characters with line feeds characters like this:

var stringVar = "I am a string that\n\
extends\n\
beyond a single line";