Sometimes, we want to wrap a long JavaScript template literal line to multiple lines without creating a new line in the string.
In this article, we’ll look at how to wrap a long JavaScript template literal line to multiple lines without creating a new line in the string.
Wrap a Long JavaScript Template Literal Line to Multiple Lines without Creating a New Line in the String
To wrap a long JavaScript template literal line to multiple lines without creating a new line in the string, we can use the \ character to break up the string code into multiple lines without creating a multi-line string.
For instance, we can write:
const text = `a very long string that just continues \
and continues and continues`;
console.log(text)
to create the text string with a \ between a very long string that just continues and and continues and continues .
Then we see from the console log that text is 'a very long string that just continues and continues and continues’ .
Conclusion
To wrap a long JavaScript template literal line to multiple lines without creating a new line in the string, we can use the “ character to break up the string code into multiple lines without creating a multi-line string.