719Re: console read only
- Jul 8, 2009--- In firstname.lastname@example.org, "crlender" <crlender@...> wrote:
>I did not say the test was incorrect. I only said it was inefficient and likely did not accomplish what he expected.
> "sandyhead25" <austin.cheney@> wrote:
> > You seem to have confused the result of the test for the operations
> > imposed within the test decision.
> No, the confusion is yours. Marcel's test and explanation were correct:
> > represented by a variable.
> No, typeof works on expressions (more precisely UnaryExpressions),
> including variables and object properties. That means it will also work on implicit properties of the global object, like |console|.
> > undefined object.
> > The value of that object is 'undefined' and its type is alsoNo, that is not obvious. Undefined is an object property that has a value of 'undefined' as type String. If this were obvious we would not be having this conversation.
> > 'undefined' instead of string.
> The value of undefined is undefined, obviously, and its type (as
> by typeof) is "undefined" (yes, a string).
> > The value of the undefined object, however, is always string outputIf the value of undefined is of type string then it has everything to do with the String object.
> > of 'undefined'.
> No, because as mentioned above there is no "undefined object", and the
> *value* of |undefined| has nothing to do with strings.
> > As a result you have accomplished nothing by attempting to filterThe 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'.
> > the value of the undefined object apart from its type.
> I can't make any sense of that statement. Marcel's example is the
> correct way of testing if a variable or property is defined.
> > The only way to accurately test for a variable's data type is toIf a variable is not defined you cannot test for any type other than undefined, which implies that types for values passed into that variable cannot be tested.
> > ensure it is actually assigned a value.
> and you can (and should) test for it with the typeof operator.
> I addition to what Marcel wrote, another potential drawback of theHere is how to test what I have claimed:
> suggested |if (console === undefined)| is that the special |undefined|
> value was not supported by some (very old) browsers, leading to
> the amusing error message "undefined is not defined." So, if you want
> to be ultra-compatible, typeof is the safer choice. In less ancient
> browsers, you could also test for the console object with
> |if ("console" in window)|, but then you'll have to declare |window|
> as /*global*/ to make it work with JSLint. If this check is in the
> context, |if ("console" in this)| should also work.
> I know you're new at this, but please check your facts before you
> start lecturing. Here, read this:
> It should clear a few things up for you.
> - Conrad
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
- << Previous post in topic Next post in topic >>