News for hackers. Stuff that matters.
Re:Multiline strings in JavaScript by wldlyinaccurate on Saturday July 12, 2014 @07:04AM (#8024237)
Probably worth pointing out that this won't play nice with most minification utilities unless you don't mind leaving all comments in the output.

I think for this reason I still prefer using Array.prototype.join for multiline strings:

    var str = [
        '<!doctype html>',
        '<html>',
            '<body>',
                '<h1>❤ unicorns</h1>',
            '</body>',
        '</html>',
    ].join('');
Re:Multiline strings in JavaScript by gravity13 on Saturday July 12, 2014 @07:16AM (#8024266)
You can also

  var str = ' \
      <!doctype html> \
      <html> \
        <body> \
          <h1>❤ unicorns</h1> \
        </body> \
      </html> \
  ' 
I find it's better than string concat because the trailing \ is just one annoying thing rather than three.
Re:Multiline strings in JavaScript by jaredmcateer on Saturday July 12, 2014 @11:41AM (#8024820)
6 months later:

    var str = ' \
        <!doctype html> \
        <html> \
          <body> \ 
            <h1>❤ unicorns</h1> \
          </body> \
        </html> \
    ' 
Help I'm maintaining your code and I get a syntax error
Re:Multiline strings in JavaScript by jasonkostempski on Saturday July 12, 2014 @01:29PM (#8025160)
HA! I (don't) see what you did there :)
Re:Multiline strings in JavaScript by msujaws on Saturday July 12, 2014 @01:37PM (#8025183)
There is a space following one of the slashes.
Re:Multiline strings in JavaScript by tekacs on Saturday July 12, 2014 @07:46AM (#8024317)
... also this is (presumably) 'joined' at parse time, rather than runtime (and so only once per execution, guaranteed).
Re:Multiline strings in JavaScript by mofle on Saturday July 12, 2014 @07:08AM (#8024248)
You can use the `/*@preserve` directive.

See: https://github.com/sindresorhus/multiline#minification

Re:Multiline strings in JavaScript by wldlyinaccurate on Saturday July 12, 2014 @07:13AM (#8024260)
Hey, thanks - that'll teach me for not reading the full page!
Re:Multiline strings in JavaScript by andrey-p on Saturday July 12, 2014 @11:49AM (#8024839)
Ooh I really really like this. Preserving newlines (one of the stated usecases for multiline) is dead easy too.

  var str = [
    //...
  ].join("\n");