Unfortunately, you can’t just assign a string like:
var string = 'this is my very long string';
There are, however, a couple of great ways to get around this. My favorite methods, personally, are the following.
var string = (<r><![CDATA[ The text string goes here. Since this is a XML CDATA section, stuff like <> work fine too, even if definitely invalid XML. ]]></r>).toString();
The major advantage of using the heredoc method is it preserves whitespace, which is super userful! As you can imagine, it’s very easy to define tabs and other whitespace by actually entering that whitespace into your string. No need for “\t.”Backslash MethodAnother method includes using a backslashes to denote end of the line in the source. This will translate to a continuous line in JS.
var string = "another long \ test string";
Of course, the traditional technique is to concatenate multiple strings together on multiple lines using the “+” operator:
var string = "really long string"+ "another even longer string";