Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I store multi line values into a JavaScript literal? [duplicate]

Tags:

javascript

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

like image 377
Shamoon Avatar asked Sep 15 '25 16:09

Shamoon


1 Answers

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

window.lastSavedContents = "test\n\ntester";
like image 145
Ernest Friedman-Hill Avatar answered Sep 18 '25 08:09

Ernest Friedman-Hill