Search the web
Sign In
New User? Sign Up
jslint_com · JSLint.com
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Want your group to be featured on the Yahoo! Groups website? Add a group photo to Flickr.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
console read only   Message List  
Reply | Forward Message #729 of 993 |
Re: console read only

--- In jslint_com@yahoogroups.com, "crlender" <crlender@...> wrote:
>
> "sandyhead25" <austin.cheney@> wrote:
> > Unary operators are typically regarded as poor practice in
> > JavaScript
>
> They're not.

They why are unary operators frowned upon by the jslint tool?

> > and still require use of a name variable.
>
> They don't.

Operators require something to act upon.

> > > No. There is no "JavaScript undefined object". |undefined| is a
> > > primitive value.
> >
> > We were both wrong. undefined is an object property. All other
> > types are, however, objects.
>
> |undefined| is not an object property, it's a primitive value. If all
> types were objects, typeof would return "object" for each of them,
> and would be quite useless.
>
> typeof "" --> "string"
> typeof new String("") --> "object"
>
> What you probably meant to say is that for most types, there exists
> a built-in constructor with a similar name:
>
> "object" --> Object
> "number" --> Number
> "string" --> String
> "boolean" --> Boolean
> "function" --> Function
>
> "undefined" --> no constructor
> "unknown" --> no constructor (used by IE)
> "other-host-defined-type" --> depends on host environment

Functions are objects. Types are derived from the few named constructor
functions built into the language.

> > > No, because as mentioned above there is no "undefined object",
> > > and the *value* of |undefined| has nothing to do with strings.
> >
> > If the value of undefined is of type string then it has everything
> > to do with the String object.
>
> The value of |undefined| can never be a string. Its value is
> |undefined|, and its type is "undefined".

No, undefined is a type not a string, and like all types they are output as
string labels.

> > The root of your confusion seems vested in collusion of value and
> > type, which are not related except for type Number. String object
> > is a perfect example of this because the object's name is String
> > with a capital 'S', but the type represented by that object is
> > 'string' with a lowercase 's'.
>
> Here's a String object: new String("hey").
> It doesn't have a name. It has a constructor (String), and it has a
> type ("object").

It does have a name. Its name is an instance of the original String function,
and so String is its name.

> > If a variable is not defined you cannot test for any type other
> > than undefined,
>
> Sure I can:
> var foo;
> if (typeof foo == "object") { ... }
>
> Doesn't make a lot of sense this way, but it could happen if the
> variable foo were declared somewhere else (not your code), and you
> don't know if it's currently defined or not.
>
> > which implies that types for values passed into
> > that variable cannot be tested.
>
> I don't understand what you mean by that.

You don't understand because you broke this out of its context. You referred to
a single statement into two separate parts, and so the remaining fragment is an
incomplete thought. Your example is flawed logic, because you cannot determine
if a variable is storing an object if it is never provided any data or data type
to represent.

> > Here is how to test what I have claimed:
> >
> > xyzpdq === undefined //true
> > typeof(xyzpdq) === 'undefined' //true
> > typeof(undefined) === 'undefined' //true
> > typeof(typeof(undefined)) === 'string' //true
> > typeof(String) === 'function' //true
> > typeof(typeof(String)) === 'string' //true
> >
> > I know that this is accurate, because this is how JavaScript
> > evaluates in Firefox. If the ECMA standard is in disagreement with
> > me then Firefox's interpretation of JavaScript is nonstandard or
> > the standard is wrong.
>
> By definition, the specification can't be wrong (except for errata,
> which are also available for download). Testing the type of
> |typeof|'s return value doesn't make sense, because typeof will
> always return a string. Your first example is dangerous and will blow
> up with a ReferenceError if xyzpdq can not be resolved along the scope
> chain.
>
>
> - Conrad
>

Specifications are often wrong when they differ from the de facto implementation
of the concepts addressed. This was the nature of the web during the years of
the browser wars.

My question is why would you ever perform any test on an undeclared variable?
Why wouldn't you avoid such sloppiness by writing your code correctly and using
JSLint to find your undeclared and unused variables?




Thu Jul 9, 2009 9:56 pm

sandyhead25
Offline Offline
Send Email Send Email

Forward
Message #729 of 993 |
Expand Messages Author Sort by Date

With the newest version of JSLint I am having a frequent error on this code block: if (typeof console==="undefined") { console = { log: function() {}, dir:...
Noah Peters
boyopeg
Offline Send Email
Jun 29, 2009
5:00 pm

... Either turn off the Assume a Browser option, or add this comment: /*global console: true*/...
Douglas Crockford
douglascrock...
Offline Send Email
Jun 29, 2009
6:04 pm

... Awesome, thanks!...
Noah Peters
boyopeg
Offline Send Email
Jun 29, 2009
8:12 pm

... Why would you use typeof(console) === "undefined" instead of console === undefined which should be the same thing, but faster?...
sandyhead25
Offline Send Email
Jul 5, 2009
12:33 pm

... if (console === undefined) // could raise ReferenceError if console is not defined if (typeof console === 'undefined') // is safer, tests for the type of...
marcelduran
Offline Send Email
Jul 6, 2009
3:03 am

... You seem to have confused the result of the test for the operations imposed within the test decision. The typeof operator only tests for the type of the...
sandyhead25
Offline Send Email
Jul 7, 2009
11:16 pm

... No, typeof works on expressions (more precisely UnaryExpressions), including variables and object properties. That means it will also work on implicit...
crlender
Offline Send Email
Jul 8, 2009
1:03 am

... I did not say the test was incorrect. I only said it was inefficient and likely did not accomplish what he expected. ... Unary operators are typically...
sandyhead25
Offline Send Email
Jul 9, 2009
3:27 am

... Firefox. If the ECMA standard is in disagreement with me >then Firefox's interpretation of JavaScript is nonstandard or the standard is wrong. Wow ! Be...
Alexandre Morgaut
morgaut_a
Offline Send Email
Jul 9, 2009
10:05 am

... They're not. ... They don't. ... types were objects, typeof would return "object" for each of them, and would be quite useless. typeof "" -->...
crlender
Offline Send Email
Jul 9, 2009
2:56 pm

... They why are unary operators frowned upon by the jslint tool? ... Operators require something to act upon. ... Functions are objects. Types are derived...
sandyhead25
Offline Send Email
Jul 9, 2009
9:57 pm

... What?...
Douglas Crockford
douglascrock...
Offline Send Email
Jul 9, 2009
10:03 pm

... The most significantly common increment and decrement operators are frowned upon by the tool. The unary plus operator is not frowned upon, but is...
sandyhead25
Offline Send Email
Jul 10, 2009
9:10 am

right, but my point was: "if (console === undefined)" only works when console variable is defined. [Non-text portions of this message have been removed]...
Marcel Duran
marcelduran
Offline Send Email
Jul 8, 2009
1:10 am

... No, because if the variable is defined then "if (console === undefined)" will not work, or rather it will evaluate to false. If console is defined then...
sandyhead25
Offline Send Email
Jul 9, 2009
2:02 am

by "work" I meant "will evaluate the expression" not the result itself.again: if console is not defined, your test, if (console === undefined) will raise a...
Marcel Duran
marcelduran
Offline Send Email
Jul 9, 2009
2:37 am

... I have discovered the root of this complication. If a variable is declared but not assigned or not used this text works perfectly fine. If the variable...
sandyhead25
Offline Send Email
Jul 9, 2009
3:35 am

... 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...
pauanyu
Offline Send Email
Jul 10, 2009
8:49 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help