Skip to content

Instantly share code, notes, and snippets.

@thirdj
Created June 17, 2013 01:35
Show Gist options
  • Select an option

  • Save thirdj/5794171 to your computer and use it in GitHub Desktop.

Select an option

Save thirdj/5794171 to your computer and use it in GitHub Desktop.
Multi-line strings in JavaScript
// 1.
var lines = [
'<!DOCTYPE html>',
'<html>',
'<body>',
'<h1>Hello, world!</h1>',
'</body>',
'</html>'
].join('\n');
// 2.
var html = (function () {/*
<!DOCTYPE html>
<html>
<body>
<h1>Hello, world!</h1>
</body>
</html>
*/}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1];
// 3.
var data = "
Hi there, \
Welcome to this post. \
Thanks \
Me \
";
// 4.
var lines = "".concat( "'<!DOCTYPE html>",
"<html>",
"...etc" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment