JavaScript lacks a designated here-document syntax as found in Ruby. However, it does offer alternative methods for representing multiline strings.
ES6 introduces template literals, a type of literal designated by backticks (`). Template literals can be multiline, as seen in the following example:
var html = ` <div> <span>Some HTML here</span> </div> `;
For older versions of JavaScript (prior to ES6), you can resort to escaping newline characters within a string:
"foo \ bar"
This technique allows for string continuation across multiple lines.
The above is the detailed content of How Can I Assign Multiline Strings to Variables in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!