-1

EDIT OK, I've realised there is already an answer answering this question with NO: Creating multiline strings in JavaScript

Thanks for all escaping/concatenating answers, but it is not what I needed. END EDIT

In Python it is possible to define string variables having many lines by the notation

"""
many
many lines
"""

Is there something like this in JavaScript?

Community
  • 1
  • 1
Valentin H
  • 7,240
  • 12
  • 61
  • 111

2 Answers2

-1

I think you could use it like this:

var str = 'many\n' +
          'many lines';
Maxim Zhukov
  • 10,060
  • 5
  • 44
  • 88
-1

Although such a thing does not exist in Javascript there is a way around it. Instead of the occasional """ """, you can add a \ at the end of each line. That in turn will create a "Multi-line string". Here is an example:

var myString = "This is \
                my multi \
                line string";

EDIT

I thought I should also point this out. Another way of accomplishing this is to concatenate together the strings, like so:

var myString = "This is" +
               "my multi" +
               "line string";
Michael Jones
  • 2,222
  • 18
  • 32