Sometimes, we want to create a JavaScript string with new line but not using \n.
In this article, we’ll look at how to create a JavaScript string with new line but not using \n.
How to create a JavaScript string with new line but not using \n?
To create a JavaScript string with new line but not using \n, we can use template literals.
For instance, we write
const foo = `Bob
is
cool`;
to define the foo
template literal.
Then whitespaces and new lines are preserved with template literals.
Conclusion
To create a JavaScript string with new line but not using \n, we can use template literals.