You can break a statement over several lines with no need to do anything special. Just put the semicolon (;
) at the end of your statement so that it's clear where it is supposed to end.
When a line doesn't end in a semicolon, JS will look at what comes next to see where it makes sense to insert a semicolon and end the statement. (The (sort of) exception is return
.)
If you want to break up a long string, just break it into smaller strings and concatenate.
The example you posted:
$('#image_holder').append('<div id="holder_info"><h5>Creatology Concept Design Academy (Final College Yeah Exibition):</h5><p>For my final year at Weston College, we were asked to invent a company and produce a series of designs related, this included</p></div>');
can easily become:
$('#image_holder')
.append(
'<div id="holder_info"><h5>Creatology Concept Design Academy ' +
'(Final College Yeah Exibition):</h5>' +
'<p>For my final year at Weston College, we were asked to ' +
'invent a company and produce a series of designs related, ' +
'this included</p></div>'
);
(The indentation is just a matter of style, not a requirement.)
This works because JS can't insert a semicolon anywhere in those lines and have the code on both side of the semicolon make syntactical sense.
The reason this doesn't work with
return
true;
or
return
this;
is because return;
can be a statement by itself and so can true
or this
or anything that normally comes after return
, so JS inserts a semicolon after return
. This isn't really an exception, just more of a potential trap one has to be aware of.
Also, I've asked nicely so there is no need to be so rude, I would've hoped this website helps to provide answers and not belittle people for being beginners in coding.
– Martin Bodger Jun 03 '13 at 14:18