How to create multiline strings in JavaScript

October 13, 2022 No comments javascript string multiline heredoc

Introduction

In JavaScript, there are situations when we wish to create multiline strings. In this article, we'll look at how to do it.

How to create multiline strings in JavaScript

To create multiline strings in JavaScript we can use template literals.

Template literals are a brand-new form of literal introduced by ECMAScript 6 (ES6). Variable interpolation is only one of their many properties, but more significantly for our subject, they may be multiline.

const html = `
  <div>
    <span>Some HTML here</span>
  </div>
`;

Conclusion

In this article, we learned how to create multiline strings in JavaScript.

{{ message }}

{{ 'Comments are closed.' | trans }}