javascript - can i add indendented code in a js file? -


this question has answer here:

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

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -