Matt
Matt

Reputation: 1923

Eclipse typing code on multiple lines

When I try to type text (between "") in javascript, I have to write everything on 1 line. I can't press enter because my code woudn't be valid then.

Appearantly you can't type on multiple lines in javascript. Is this correct or did I make a mistake?

Example:

var htmlcode = "<strong>29 juni 2013</strong> <br/> 22u";
//This works

var htmlcode = "<strong>29 juni 2013</strong> 
<br/> 
22u";
//This doesn't work

Upvotes: 0

Views: 424

Answers (2)

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28757

Inside of Eclipse, there is an option that could help. Go to Preferences -> JavaScript -> Editor -> Typing. On the page, enable "Wrap automatically" and "Escape text...". This will ensure that if you press enter while inside of a string, quotes, \n, and + will be added appropriately.

Upvotes: 1

Chris Forrence
Chris Forrence

Reputation: 10104

If you want to break up code to be on multiple lines, what you can do is either of the following:

// Concatenate to the string
var htmlcode = "<strong>29 juni 2013</strong> "
    + "<br/> "
    + "22u";

or

// Use backslashes at the end of each line. May not be supported everywhere,
//   so I'd avoid this approach.
var htmlcode = "<strong>29 juni 2013</strong> \
<br/> \
22u";

Upvotes: 3

Related Questions