Creating multiline strings in JavaScript

JavaScript Template literals (Template strings) allow you to create a string that spans multiple lines.
const mString = `First line - Second Line - Third Line`;
Output: First line - Second Line - Third Line

Template literals

Template literals (Template strings) are literals delimited with backtick (`) characters, allowing for multi-line strings.
run this source code Browser View

Full Source | JavaScript
<!DOCTYPE html> <html> <body> <h2>JavaScript Multiline String</h2> <p id="demo"></p> <script> const mString = `First line - Second Line - Third Line`; document.getElementById("demo").innerHTML = mString; </script> </body> </html>

Using JavaScript join()

JavaScript join() method allow you to create a string that spans multiple lines. The join() method returns an array as a string. This method does not change the original array. Also, any separator can be specified. The default is comma (,).
var mString = ['<div id="mID">', 'First Line<br />', 'Second Line<br />', 'Third Line<br />', '<a href="#Ref">MyLink</a>', '</div>' ].join('\n');
run this source code Browser View

Full Source | JavaScript
<!DOCTYPE html> <html> <body> <h2>JavaScript Multiline String</h2> <p id="demo1"></p> <script> var mString = ['<div id="mID">', 'First Line<br />', 'Second Line<br />', 'Third Line<br />', '<a href="#Ref">MyLink</a>', '</div>' ].join('\n'); document.getElementById("demo1").innerHTML = mString; </script> </body> </html>

Using JavaScript + Operator

JavaScript + Operator allow you to create a string that spans multiple lines.
var mString = "First Line - " + "Second Line - " + "Third Line";
run this source code Browser View

Full Source | JavaScript
<!DOCTYPE html> <html> <body> <h2>JavaScript Multiline String</h2> <p id="demo3"></p> <script> var mString = "First Line - " + "Second Line - " + "Third Line"; document.getElementById("demo3").innerHTML = mString; </script> </body> </html>