javascript - can i add indendented code in a js file? -
this question has answer here:
- creating multiline strings in javascript 34 answers
below link js code
non indented : http://jsfiddle.net/bsr1/ucg6v1v0/
var dataabc = '<div class="message7">focus shifted here</div>'; alert("*");
indented http://jsfiddle.net/bsr1/1dtrz0au/
var dataabc = '<div class="message7"> focus shifted here </div>'; alert("*");
i know 2nd 1 results in js error.is there nay way can indent js code without erorr
a string cannot declared across multiple lines.
option 1 - concatenate:
var dataabc = '<div class="message7">' + 'focus shifted here' + '</div>';
option 2 - escape newline backslash:
var dataabc = '<div class="message7">\ focus shifted here\ </div>';
i advise against option 2, since relies on right amount of whitespace after \
, , not ideal minification.
on bright size, es6 introduce template strings.
Comments
Post a Comment