gafasmill gafasmill - 3 months ago 6
Javascript Question

Concatenate strings on multiple lines in JavaScript

I have some code that goes like this:

var css = '.myclass { text-align: center .... };


The about can get really long.

Is there a var to add multiple lines to then be merged together like:

var
css = '.myclass { text-align: center .... };
+css = '.myclass { something else .... };


Then css with be a merge of both lines?

Answer

Try:

var css = '.myclass { text-align: center .... };' + 
          '.myclass { something else .... };';

Or:

var css = [
           '.myclass { text-align: center .... };',
           '.myclass { something else .... };'
          ].join("\n");
Comments