Logo

Programming-Idioms

History of Idiom 48 > diff from v34 to v35

Edit summary for version 35 by programming-idioms.org:
[JS] Several ways -> new impls 2129 and 2130

Version 34

2017-10-01, 11:28:01

Version 35

2017-10-01, 11:30:44

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 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.`;
Code
let s = "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
By concatenation.
Doc URL
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#Long_literal_strings
Origin
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String