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

Unexpected '0'

Expand Messages
  • ia_perdomo
    Hi all, I have a piece of code that is not JSLint complaint: // This is a simplified version of the original code just for test-case function f(p) { var i = (0
    Message 1 of 2 , May 16, 2011
    View Source
    • 0 Attachment
      Hi all,

      I have a piece of code that is not JSLint complaint:

      // This is a simplified version of the original code just for test-case

      function f(p) {
      var i = (0 - p);
      // do something with i
      console.log(i);
      }
      f(2);


      JSLint is reporting the following problem:

      Problem at line 2 character 12: Unexpected '0'.

      I also tested it removing the parens with the same error message.

      Can you explain me why 0 is a unexpected value? Is this a bug?

      Thanks,

      Iván
    • Jordan
      Because `-p` is more clear than `0 - p`, just like `x` is more clear than `1 * x`. - Jordan
      Message 2 of 2 , May 16, 2011
      View Source
      • 0 Attachment
        Because `-p` is more clear than `0 - p`, just like `x` is more clear than `1 * x`.

        - Jordan

        --- In jslint_com@yahoogroups.com, "ia_perdomo" <ivan.perdomo.hn@...> wrote:
        >
        > Hi all,
        >
        > I have a piece of code that is not JSLint complaint:
        >
        > // This is a simplified version of the original code just for test-case
        >
        > function f(p) {
        > var i = (0 - p);
        > // do something with i
        > console.log(i);
        > }
        > f(2);
        >
        >
        > JSLint is reporting the following problem:
        >
        > Problem at line 2 character 12: Unexpected '0'.
        >
        > I also tested it removing the parens with the same error message.
        >
        > Can you explain me why 0 is a unexpected value? Is this a bug?
        >
        > Thanks,
        >
        > Iván
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.