Loading ...
Sorry, an error occurred while loading the content.

Re: Assignment in if statement + Move the invocation into the parens...

Expand Messages
  • Merlin
    ... No. There are ways around it, if you really must: var a, b; if (a === b) { a = 1; } // OK if (a = b) { a = 1; } // NOT OK if (!!(a = b)) { a = 1; } // OK
    Message 1 of 2 , Oct 8, 2011
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "m_blasz" <blasz_2000@...> wrote:
      >
      > I have 2 questions.
      >
      > 1. Is there a JSLint option to tolerate variable assignments in if statements? If so, which one?
      >

      No.

      There are ways around it, if you really must:

      var a, b;
      if (a === b) { a = 1; } // OK
      if (a = b) { a = 1; } // NOT OK
      if (!!(a = b)) { a = 1; } // OK

      > 2. Why should we 'Move the invocation into the parens that contain the function'?

      FRED = (function() { .... }());

      looks clearer than

      FRED = (function() { .... })();
    Your message has been successfully submitted and would be delivered to recipients shortly.