JavaScript - Multiple Line Literals

Aus Wikizone
Wechseln zu: Navigation, Suche

var html = `

   Some HTML here

`;

Browser support is OK, but you can use transpilers to be more compatible.

var myString = 'A rather long string of English text, an error message ' +

     'actually that just keeps going and going -- an error ' +
     'message to make the Energizer bunny blush (right through ' +
     'those Schwarzenegger shades)! Where was I? Oh yes, ' +
     'you\'ve got an error and all the extraneous whitespace is ' +
     'just gravy.  Have a nice day.';

Dont use

var myString = 'A rather long string of English text, an error message \

                 actually that just keeps going and going -- an error \
                 message to make the Energizer bunny blush (right through \
                 those Schwarzenegger shades)! Where was I? Oh yes, \
                 you\'ve got an error and all the extraneous whitespace is \
                 just gravy.  Have a nice day.';