3

Possible Duplicates:
a more graceful multi-line javascript string method
Multiline strings in Javascript

window.lastSavedContents = "test

tester";

That's my JavaScript Code. I get a firebug error saying:

unterminated string literal [Break On This Error] window.lastSavedContents = "test

Community
  • 1
  • 1
Shamoon
  • 41,293
  • 91
  • 306
  • 570

3 Answers3

7

Indeed; that's simply not valid syntax. Use "\n" to represent a newline:

window.lastSavedContents = "test\n\ntester";
Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186
1

If you want to mark new line in a JavaScript value you have t put there a newline character by putting \n:

var test = "test\n\ntest";

You can also visually expose new lines by escaping ends of lines like this:

var test = "test\n\
\n\
test";

http://jsfiddle.net/grcLH/1/

pepkin88
  • 2,742
  • 20
  • 19
-2

You can concatenate it, of course:

var stringTxt = "";

stringTxt += "test";
stringTxt += "tester";

window.lastSavedContents = stringTxt;
orolo
  • 3,951
  • 2
  • 30
  • 30