How to use Javascript multiline string ?

In this article, we have discussed the usage of the javascript multiline string using the template literals.

Template literals are string literals enclosed by the backticks(“), allowing multiline strings and embedded expressions. You can also use string interpolation features with them.  These literals can also hold placeholders which are denoted by $ symbol and curly braces like ${expression}.

A new line character inserted in the source are part of the template literals. The below example shows the usage of the multiline string using template literals.

console.log(`This is the first line

This is second line`);

The below example shows the usage of the multiline strings with expressions using the template literals.

var num1 = 3;

var num2 = 2;

console.log(`Five is ${num1 + num2} and

not ${2 * num1  + num2}.`);

// "Five is 5 and

// not 10."

This is how to use the javascript multiline string with the help of the template literals.

See also:

Javascript string to int

Thanks for reading this tutorial. If you have any questions or improvements with respect to this tutorial, Please feel free the comment below or send me an email at [email protected]

Summary
How to use Javascript multiline string
Article Name
How to use Javascript multiline string
Description
This article explains the usage of the javascript multiline string along with the expressions(placeholders for a dynamic value) using the template literals with examples.
Author
Publisher Name
askvikram.com
Publisher Logo

Leave a Comment