I have a jade variable declared like this:
BUTTONS = { more_blue: {caption: BUTTONS_CAPTIONS.more, style: BUTTONS_STYLES.blue}, more_red: {caption: BUTTONS_CAPTIONS.more, style: BUTTONS_STYLES.red}, see: {caption: BUTTONS_CAPTIONS.see, style: BUTTON_STYLE_PHOTOS}, see_photos: {caption: BUTTONS_CAPTIONS.see_photos, style: BUTTON_STYLE_PHOTOS}, program : {caption: BUTTONS_CAPTIONS.program, style: BUTTON_STYLE_PROGRAM}, see_program : {caption: BUTTONS_CAPTIONS.see_program, style: BUTTON_STYLE_PROGRAM} }
but I would like it to be more readable like this:
BUTTONS = { more_blue: {caption: BUTTONS_CAPTIONS.more, style: BUTTONS_STYLES.blue}
, more_red: {caption: BUTTONS_CAPTIONS.more, style: BUTTONS_STYLES.red}
, see: {caption: BUTTONS_CAPTIONS.see, style: BUTTON_STYLE_PHOTOS}
, see_photos: {caption: BUTTONS_CAPTIONS.see_photos, style: BUTTON_STYLE_PHOTOS}
, program : {caption: BUTTONS_CAPTIONS.program, style: BUTTON_STYLE_PROGRAM}
, see_program : {caption: BUTTONS_CAPTIONS.see_program, style: BUTTON_STYLE_PROGRAM}
}
but this code doesn't compile even if I add backslashes at the end of each line. Are there any workarounds?
You can declare multiple variables in a single line. However, there are more efficient ways to define numerous variables in JavaScript. First, define the variables’ names and values separated by commas using just one variable keyword from var, let, or const.
You can declare multiple variables in a single line. However, there are more efficient ways to define numerous variables in JavaScript. First, define the variables’ names and values separated by commas using just one variable keyword from var, let, or const. Click on the following link to see the working of the code segment.
Someone asked me the other day how to declare a string over multiple lines in jQuery. It’s actually plain JavaScript and can be done by simply adding the escape character backslash “” after each line. As you can see we simply add the backslash to the end of each line to tell the interpreter it’s part of the same long string.
The most common technique of declaring and initializing JavaScript variables is to write each variable on its line, as in: Click on the following link to see the working of the code segment. You can declare multiple variables in a single line.
Jade now supports multineline variables, as described in the docs:
-
list = ["Uno", "Dos", "Tres",
"Cuatro", "Cinco", "Seis"]
each item in list
li= item
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With