How can I assign a multiline string to a variable in JavaScript?

I’m trying to convert some Ruby code that uses a multiline string into JavaScript. In Ruby, I can write:

text = <<"HERE"
This
Is
A
Multiline
String
HERE

I want to achieve the same effect in JavaScript, storing multiple lines of text in a single variable.

What’s the best way to handle multiline string javascript? Are there specific syntax options or modern features (like template literals) that make this easy?

For example, I’d like the variable to contain:

This
Is
A
Multiline
String

without having to concatenate individual strings manually.

Modern JS has template literals with backticks:

const text = `
This
Is
A
Multiline
String
`;
console.log(text);

No need for concatenation or \n.

If you’re working in older JS, you can concatenate:

const text = "This\n" +
             "Is\n" +
             "A\n" +
             "Multiline\n" +
             "String";

It works, but it’s verbose.

Tip: template literals also support interpolation:

const name = “Alice”; const text = Hello ${name}, This is a multiline string.;

Super useful if you want variables inside the text.