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

Re: console read only

Expand Messages
  • sandyhead25
    ... The most significantly common increment and decrement operators are frowned upon by the tool. The unary plus operator is not frowned upon, but is
    Message 1 of 18 , Jul 10, 2009
    • 0 Attachment
      --- In jslint_com@yahoogroups.com, "Douglas Crockford" <douglas@...> wrote:
      >
      > --- In jslint_com@yahoogroups.com, "sandyhead25" <austin.cheney@>
      > > They why are unary operators frowned upon by the jslint tool?
      >
      > What?
      >

      The most significantly common increment and decrement operators are frowned upon by the tool. The unary plus operator is not frowned upon, but is unpredictable if used against an object or array of various data types. The unary plus operator seems useless if not testing a value for type Number. Multiplication by 1 is significantly more reliable for testing if a value is of type Number as it takes the full value of a variable into consideration. The minus operator appears useful for converting values of type Number into polar opposites, but it is still subject to the same problems as the unary plus operator.

      I suppose the tool does not raise issue with plus or minus unary operators, but I never see these used and have learned to avoid them in my own code as bad style.
    • pauanyu
      ... This whole thread has spiraled out of control. Here s the simple answer: If you use (console === undefined), and console has not been declared, it will
      Message 2 of 18 , Jul 10, 2009
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "sandyhead25" <austin.cheney@...> wrote:
        >
        > Why would you use
        > typeof(console) === "undefined"
        > instead of
        > console === undefined
        > which should be the same thing, but faster?
        >

        This whole thread has spiraled out of control. Here's the simple answer:

        If you use (console === undefined), and console has not been declared, it will throw a ReferenceError.

        If you use (typeof console === "undefined"), and console has not been declared, it will *not* throw a ReferenceError.

        There IS a difference between an undeclared variable and an undefined variable. A variable can be declared but undefined. An undeclared variable will throw a ReferenceError, but an undefined variable will not.

        That is why it is better to use typeof, because it will not throw a ReferenceError for undeclared variables.
      Your message has been successfully submitted and would be delivered to recipients shortly.