The newline character is \n in JavaScript and many other languages. All you need to do is add \n character whenever you require a line break to add a new line to a string.
If the last line is an instruction that has an obvious end (ends in a ; or a } ), you don't have to end it in with a newline. If the last line is a comment or has no ending, you should put a newline. And if you only have one JavaScript file, you don't have to worry at all.
The <br> element will break a line wherever it renders.
<br>: The Line Break element. The <br> HTML element produces a line break in text (carriage-return).
What are the dangers of breaking a line of long code up at a close parenthesis?
When could a semicolon be automatically inserted by Javascript (presumably that is the danger, right?).
Why is using a )
as a line breaker "frowned upon" by JSLint?
In Javascript I sometimes see one long line of code broken up at a )
like this (example):
function ()
{
or like this (example):
object.methodOne()
.methodTwo();
But when reading the line break expectations for jsLint, it says:
As a further defense against the semicolon insertion mechanism, JSLint expects long statements to be broken only after one of these punctuation characters or operators:
, ; : { } ( [ = < > ? ! + - * / % ~ ^ | &
== != <= >= += -= *= /= %= ^= |= &= << >> || &&
=== !== <<= >>= >>> >>>=
JSLint does not expect to see a long statement broken after an identifier, a string, a number, closer, or a suffix operator:
. ) ] ++ --
So the close parenthesis is singled out as a line breaker that JSLint "doesn't expect to see."
I would prefer to use
function()
{
since I find it more readable, and I already use it in other languages, but currently I use:
function () {
Could I safely use the )
to break up long lines?
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