Multiline Strings in JavaScript
In JavaScript, there are two ways to assign a multiline string to a variable.
ES6 Template Literals
With ES6, you can use template literals to define multiline strings. Template literals are delimited by backticks (`), and they support line breaks and interpolation.
const html = ` <div> <span>Some HTML here</span> </div> `;
Escaped Line Breaks
In ES5, you can escape line breaks using the n character. This allows you to create multiline strings, but it's not as elegant as using template literals.
const foo = "foo \ bar";
Note: Browser support for template literals is generally good, but you may need to use a transpiler for older browsers.
The above is the detailed content of How Can I Create Multiline Strings in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!