Logo

Programming-Idioms

History of Idiom 48 > diff from v31 to v32

Edit summary for version 32 by glmdgrielson:
[JS] Didn't see the requirement for s to be the string

Version 31

2017-09-30, 18:27:55

Version 32

2017-09-30, 18:30:35

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.`;
Code
let s = "This is a very long string which needs " +
                 "to wrap across multiple lines because " +
                 "otherwise my code is unreadable.";
let r = "This is a very long string which needs \
to wrap across multiple lines because \
otherwise my code is unreadable.";
let t = `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!
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
Origin
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String