1. Using backticks
var htmlString = `Say hello to multi-line strings!`; var html = ` <div> <span>Some HTML here</span> </div> `;
The above feature is a result of template literals introduced in ECMAScript (ES6). It also supports variable interpolation in strings.
When you print such strings in console, or HTML they will be displayed as a multiline string.
console.log(htmlString); Say hello to multi-line strings! console.log(html); <div> <span>Some HTML here</span> </div>
2. Using backslash
You can also use backslash to create multiline strings, as shown below. In this case, you can use double and single quotes, instead of using backticks.
var htmlString = "Say hello to \ multi-line \ strings!"; var html = " \ <div> \ <span>Some HTML here</span> \ </div> \ ";
You can also store strings as array elements and join them using backslash to get a multiline string, but the above methods are faster, especially for long strings.