Logo

Programming-Idioms

History of Idiom 48 > diff from v30 to v31

Edit summary for version 31 by glmdgrielson:
New JS implementation by user [glmdgrielson]

Version 30

2017-05-27, 22:31:18

Version 31

2017-09-30, 18:27:55

Idiom #48 Multi-line string literal

Assign to variable s a string literal consisting in several lines of text

Idiom #48 Multi-line string literal

Assign to variable s a string literal consisting in several lines of text

Extra Keywords
multiline raw
Extra Keywords
multiline raw
Code
let longString1 = "This is a very long string which needs " +
                 "to wrap across multiple lines because " +
                 "otherwise my code is unreadable.";
let longString2 = "This is a very long string which needs \
to wrap across multiple lines because \
otherwise my code is unreadable.";
let longString3 = `This is a very long string which needs 
to wrap across multiple lines because 
otherwise my code is unreadable.`;
Comments bubble
There's a few ways to do this.
There is the concatenation method as seen in longString1.
Backslash-newline also works but requires no indentation as seen in longString2.
And ES6 allows so-called "template literals" which allow them by default!
Origin
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String