Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is it dangerous to line break after a close parenthesis in Javascript?

Tags:

People also ask

What are line breaks in JavaScript?

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.

When we are done with a line in JavaScript What do we put at the end?

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.

Which element causes browsers to automatically add a line break after the element is rendered?

The <br> element will break a line wherever it renders.

Which tag is used for break line in JavaScript?

<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?