JavaScript - Multiple Line Literals

Aus Wikizone
Version vom 6. März 2017, 09:31 Uhr von 37.49.32.84 (Diskussion) (Die Seite wurde neu angelegt: „var html = ` <div> <span>Some HTML here</span> </div> `; Browser support is OK, but you can use transpilers to be more compatible. var myString = 'A…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
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.';