7

Please assume 'use strict'; and also assume that, JSLint is on and errors cannot be ignored.

I find operators and ',' initiated lists so much more readable,

e.g.:

var i = 0
    , j = 1
    , someLongVariablename1
    , someLongVariablename2
    , someLongVariablename3
    , someLongVariablename4;

 if( (
     'dcr' === cmd
      && (action)
      && ('get' === actionHttp || 'post' === actionHttp )
      && whatever
   ) { ... }

Hence my question:
Is "Bad Line Breaking" obsolete with "use strict"?

EDITED: 'use strict'; will not prevent the execution of bad line breaking the code. It can prevent the execution of some kinds of errors.

I see that JSLint and JSHint treat bad line breaking differently. JSHint is much friendlier towards the syntax I prefer.

So that, may be a solution for others who are working on this.

Vikrant
  • 4,920
  • 17
  • 48
  • 72
Ron Wertlen
  • 830
  • 10
  • 24

1 Answers1

5

Unfortunately, strict mode doesn't disable the horror that is automatic semicolon insertion, and so "bad" line breaks remain an issue. For example:

(function() {
  "use strict";

  console.log(foo());

  function foo() {
    var a = 1, b = 2;

    return
    a + b;
  }
})();

Live Example | Source (you need to open the console and look at it)

That still logs undefined rather than 3, because ASI kicks in and adds a semicolon after the return in foo.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • We are using very strict settings in JSLint. The code you wrote is a complete JSLint anti-pattern, as JSLint gives three errors: * expected ; error * unreachable code error – Ron Wertlen Feb 18 '13 at 13:21
  • 1
    I edited the question: I am assuming rigorous use of JSLint, so that execution will NOT proceed if JSLint errors are in place. However, that really complicates the question... originally a simple question and your answer is a simply right. Am marking your answer right. – Ron Wertlen Feb 18 '13 at 13:41