Skip to content

Multiline strings in JavaScript

Find out how to create multiline strings in JavaScript. In this post we will learn various ways to create multiline strings in JavaScript. One of the ways is Template Strings which waswas introduced in ES6.

Escape new lines using \

const multilineString = 'Hello This is Poopcode.\
We write bytesized posts about trending programming stuff.\
Anything else?'

Concatenating strings

const multilineString = 'Hello This is Poopcode.' +
+ 'We write bytesized posts about trending programming stuff.' +
'Anything else?'

Template Strings

Instead of using ‘ or “, use ` (backtick) to create strings which enables us to create multiline strings.

const multilineString = `Hello This is Poopcode.
We write bytesized posts about trending programming stuff.
Anything else?`

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.