The easiest way to create a multiline string in JavaScript are backticks.
const s = `I'm
a
multiline
string`;
console.log(s);
The console output shows every word in the string s
on a new line. Exactly as we wanted.
I'm
a
multiline
string
Alternatively, you can write everything in a single line adding \n
characters.
\n
stands for new line. It’s a special character that you would see only as a line break.
const s = `I'm\na\nmultiline\nstring`;
console.log(s);
The output remains the same, with every word in the string s
being logged to the console from a new line.
I'm
a
multiline
string