JavaScript multi-line String

String manipulation is easy to learn but most difficult to master of it in JavaScript. Earlier, multi-line string was not supported by JavaScript. After 2015, string literals have introduced by ES6 (ECMAScript 6) that supports multi-line string.

Now, there are several ways to handle multi-line string. We will discuss these different methods to handle multi-line string one-by-one in this chapter.

Following are a couple of ways to work with multi-line string:

Method 1

It is the simplest way of JavaScript to show the string text in multiple lines. Use the break line tab (
) or HTML inside the document.write() function to start the text from the new line.

Example

Here is the practical implementation of multi-line string using JavaScript programming:

Copy Code

Test it Now

Output

When you will execute this code, three text strings will display you on the web that will be divided using the break line tab (
) of HTML
.

This is first line display using JavaScript.
This is second line and divided using break line tab of HTML.
Now, we again printed another new line.

Example 2: Concatenating individual string

In this example, we will simply print the multi-line string without any line break using JavaScript programming:

Copy Code

Test it Now

Output

When you will execute this code, two text paragraphs will show you on the web that will be divided using the break line tab (
) of HTML.

Javatpoint is a website of technologies, which provides tutorials of different technologies and tools. Here you will get tutorials in detail 'like theory as well as practical implementation.
We will try to provide you the best knowledge from our side. 'Student, teachers, and industry professionals can learn from here.

Example 3

This is a simple example of multi-line text printing using JavaScript programming. In this we have only used HTML
tab to break the sentences in multiple line:

Copy Code

Test it Now

Output

When you will execute this code, three paragraphs will display you on the web that will be divided using the break line tab (
) of HTML.

JavaScript is a programming language that is popular for web development at the client-side execution. This language is very light-weighted mostly used to put validations, so they check at client-side. 
Nowadays, it is very trending in market for web development.
As it also allows dynamic execution of code.

Method 2: You can also pass the text string inside

or or heading tabs (

to
) to divide them into multiple lines or paragraphs. See the code below:

Copy Code

Test it Now

Output

The above-passed line will show in multiple new lines. These lines are started from a new line using the paragraph and bold tab.

This is first line of the paragraph. 
This text will show you in bold letters in next line. 
Now, it is again a simple text line.

Method 3: In this method, we will print a multi-line string. This mostly comes into work when you want to write paragraph writing.

Example

You can write multi-line text text inside multiple HTML tabs for clear understanding of paragraph. See with help of an example:

Copy Code

Test it Now

Output

An output will display you on the web by executing the above. See the response below; you will see a Display Multiline button to show you a text string.

JavaScript multi-line String

Click this Display Multiline button and a text string will display you in multiple lines. See the output below:

JavaScript multi-line String




Contact US

Email:[email protected]

JavaScript multi-line String
10/30