00 Votes

JavaScript: Multiline Strings in Source Code

Tip by Progger99 | 2014-01-25 at 13:18

Sometimes, for reasons of clarity, it is a good idea to let a string go over multiple lines.

In JavaScript, it is not readily possible to break a string in source code just using a line break.

Unless you are using a backslash at the end of each line:

document.write("This is a text,\
reaching over two lines.");

If you close a long string with a backslash, you can simply continue the string in the next line without any problems.

Incidentally, this kind of line break "within" the string is ignored and does not have any impacts to the string. It is just the same result as if you have written the string into one line.

ReplyPositiveNegative

About the Author

AvatarThe author has not added a profile short description yet.
Show Profile

 

Related Topics

PHP: Sending an E-Mail

Tutorial | 0 Comments

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.