How to write multiple lines string in JavaScript

by Softhacker18. July 2013 18:53

As a .NET developer, I was expecting something similar to "@" operator like C#  language to write multi lines string. But unfortunately I didn't get any such operator in JavaScript. There are two ways to write multi lines text in JavaScript. Refer below sample code:

//Cleaner way of writing multi lines text in JavaScript 

var multiLinesString = "First line\

                            Second Line\

                            ..\

                        ";

 

//Another way of writing multi lines text in JavaScript 

var multiLinesString = "First line"+

                            "Second Line"+

                            "..";

Below is the sample code to write multi lines text in C# (CSharp):

//Way to write multi lines text in C# 

string multiLinesString = @"First line

                                Second Line

                                ..

                            ";

 

//Another way of writing multi lines text in C#

string multiLinesString = "First line"+

                                "Second Line"+

                                "..";

 

Add comment

biuquote
  • Comment
  • Preview
Loading

Like To Connect With US x