How to include line Breaks in ES6

How do you include a line break in JavaScript, as in the case of calling a function multiple times, that displays a set of strings on separate line?

To include a line break in a string, you can use the escape character '\n'. This creates a new line in a string:

console.log("hi \n you");


1 Like

Many thanks. I get it now.

Is this a valid syntax

console.log(outPutStuff()) \n console.log(outPutStuff()) \n console.log(outPutStuff());

If you had it all in the one console.log(), then it would be. The \n should be in a string: '\n', and will only be effective if printed.

So, is this rather correct?

console.log(outPutStuff() "\n" outPutStuff() "\n" outPutStuff());

You would have to join the strings in some way, either through concatenation or string interpolation:


console.log(outPutStuff() + "\n" +  outPutStuff() + "\n" + outPutStuff());

String interpolation:
console.log(`${outPutStuff()} \n ${outPutStuff()} \n ${outPutStuff()}`);
1 Like

Okay! Thanks for that clarification.

1 Like