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

RE: JSLint error

Expand Messages
  • Stoyan Stefanov
    Thanks Anton, (forwarding to the jslint group) YSlow has an older version of JSLint, so I pasted your test code into jslint.com and got a different error
    Message 1 of 2 , Dec 23, 2008
    • 0 Attachment
      Thanks Anton,

      (forwarding to the jslint group)

      YSlow has an older version of JSLint, so I pasted your test code into
      jslint.com and got a different error message, which doesn't look right
      to me personally, but I will leave the group to provide a better
      explanation.

      Test:
      --
      var b;
      var a = b = 123;

      JSLint response:
      --
      Error:
      Problem at line 2 character 9: Variable b was not declared correctly.
      var a = b = 123;


      Best,
      Stoyan



      -----Original Message-----
      From: Anton [mailto:aggtaa@...]
      Sent: Sunday, December 14, 2008 12:48 AM
      To: yslow@...
      Subject: JSLint error

      Name: Anton

      Email: aggtaa@...

      Message:
      Hello.

      I'm not a jslint user group member nor want to become one just to
      report a bug, so I desided to report it to you as you must be a
      concerned party.

      JSLint appears to be not accepting multiple asiignments in one
      operator. It spawns host of errors and stops analysing code. This bug
      appears in particular on jquery-1.2.6.js:
      ---
      Missing ';' line 18, char 26: ignore all
      var jQuery = window.jQuery = window.$ = function( selector, context
      )
      Expected an identifier and instead saw '='. line 18, char 27:
      ignore all
      var jQuery = window.jQuery = window.$ = function( selector, context
      )
      Stopping, unable to continue. (0% scanned) line 18, char 27: ignore
      all
      var jQuery = window.jQuery = window.$ = function( selector, context
      )
      ---

      Piece of code to reproduce:
      ---
      var b;
      var a = b = 123;
      ---
    • Douglas Crockford
      ... The var statement var a = b = 123; is a common error, with people thinking they are declaring two local variables but in reality declaring one local
      Message 2 of 2 , Dec 23, 2008
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "Stoyan Stefanov" <stoyan@...> wrote:
        > YSlow has an older version of JSLint, so I pasted your test code into
        > jslint.com and got a different error message, which doesn't look right
        > to me personally, but I will leave the group to provide a better
        > explanation.
        >
        > Test:
        > --
        > var b;
        > var a = b = 123;
        >
        > JSLint response:
        > --
        > Error:
        > Problem at line 2 character 9: Variable b was not declared correctly.
        > var a = b = 123;

        The var statement

        var a = b = 123;

        is a common error, with people thinking they are declaring two local
        variables but in reality declaring one local variable and one dreaded
        global variable. In your example, this is not the case because b was
        already declared, but it looks like a common error, and when your
        programs look like errors, it becomes harder to see the real errors.

        So whenever you use assignment as an expression, I recommend that you
        wrap it in parens to demonstrate that you actually know what you are
        doing.

        var a = (b = 123);
      Your message has been successfully submitted and would be delivered to recipients shortly.