How to break strings in more than one row without concatenating? [duplicate]

1

var str = 'foo bar foo bar foo bar foo bar foo bar foo bar' +
          'foo bar foo bar foo bar foo bar foo bar foo bar' +
          'foo bar foo bar foo bar foo bar foo bar foo bar' +
          'foo bar foo bar foo bar foo bar foo bar foo bar' +
          'foo bar foo bar foo bar foo bar foo bar foo bar'
;

However having to create add quotes ( " ) or apostrofo ' , is it possible to break a string without needing to concatenate?

    
asked by anonymous 22.09.2015 / 19:26

1 answer

4

According to this response from SOen it is possible using backslash

This:

var str = "foo bar foo bar foo bar foo bar foo bar foo bar \
foo bar foo bar foo bar foo bar foo bar foo bar";

Will result in:

  

foo bar foo bar

This:

var str = "foo\
bar";

Will result in:

  

foobar

To break the lines of the "value" you will also need to use \n and \ then:

var str = "foo bar foo bar foo bar foo bar foo bar foo bar \n\
foo bar foo bar foo bar foo bar foo bar foo bar";
    
22.09.2015 / 19:26