Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
160
rated 0 times [  162] [ 2]  / answers: 1 / hits: 15494  / 14 Years ago, tue, march 22, 2011, 12:00:00

The question is:



What is the JavaScript method to store a multiline string into a variable like you can in PHP?


More From » string

 Answers
25

If by 'multiline string' you mean a string containing linebreaks, those can be written by escaping them using n (for newline):



var multilineString = 'Line 1nLine 2';
alert(multilineString);
// Line 1
// Line 2


If you mean, how can a string be written across multiple lines of code, then you can continue the string by putting a backslash at the end of the line:



var multilineString = 'Line 
1nLine 2';
alert(multilineString);
// Line 1
// Line 2

[#93141] Monday, March 21, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
pierce

Total Points: 315
Total Questions: 103
Total Answers: 89

Location: Svalbard and Jan Mayen
Member since Mon, Jun 7, 2021
3 Years ago
;