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

719Re: console read only

Expand Messages
  • sandyhead25
    Jul 8, 2009
      --- In jslint_com@yahoogroups.com, "crlender" <crlender@...> wrote:
      >
      > "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:

      I did not say the test was incorrect. I only said it was inefficient and likely did not accomplish what he expected.

      > > The typeof operator only tests for the type of the value
      > > 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|.

      Unary operators are typically regarded as poor practice in JavaScript and still require use of a name variable. This is not really relevant to the subject at hand and does not challenge what I said. typeof returns the object or property type of a variable name as a string value.

      > > If a variable is undefined then it is assigned to the JavaScript
      > > undefined object.
      >
      > 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.

      > > The value of that object is 'undefined' and its type is also
      > > 'undefined' instead of string.
      >
      > The value of undefined is undefined, obviously, and its type (as
      > returned
      > by typeof) is "undefined" (yes, a string).

      No, 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.

      > > The value of the undefined object, however, is always string output
      > > of 'undefined'.
      >
      > 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.

      > > As a result you have accomplished nothing by attempting to filter
      > > 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 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 only way to accurately test for a variable's data type is to
      > > ensure it is actually assigned a value.
      >
      > That's nonsense. "undefined" is one of the basic types in JavaScript,
      > and you can (and should) test for it with the typeof operator.

      If 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.

      > I addition to what Marcel wrote, another potential drawback of the
      > 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
      > global
      > 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:
      >
      > http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pd\
      > f
      >
      > It should clear a few things up for you.
      >
      >
      > - Conrad
      >

      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.
    • Show all 18 messages in this topic