Re: console read only
- --- In firstname.lastname@example.org, "Douglas Crockford" <douglas@...> wrote:
>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.
> --- In email@example.com, "sandyhead25" <austin.cheney@>
> > They why are unary operators frowned upon by the jslint tool?
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.
- --- In firstname.lastname@example.org, "sandyhead25" <austin.cheney@...> wrote:
>This whole thread has spiraled out of control. Here's the simple answer:
> Why would you use
> typeof(console) === "undefined"
> instead of
> console === undefined
> which should be the same thing, but faster?
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.