Multiline String Variables in JavaScript

0
0

This works:

var htmlString = "
This is a string.
"
;

This fails:

var htmlSTring = "<div>
  This is a string.
</div>";

Sometimes this is desirable for readability.

Add backslashes to get it to work:

var htmlSTring = "
\ This is a string.\
"
;
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.