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 :)
There is a space following one of the slashes.
... also this is (presumably) 'joined' at parse time, rather than runtime (and so only once per execution, guaranteed).
You can use the `/*@preserve` directive.
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!
I think for this reason I still prefer using Array.prototype.join for multiline strings: