Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > undefined vs. undefined (was: new Array() vs [])

Reply
Thread Tools

undefined vs. undefined (was: new Array() vs [])

 
 
VK
Guest
Posts: n/a
 
      09-09-2006
(see the post by ASM in the original thread; can be seen at
<http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b>
as an option)

As that is not in relevance to "new Array() vs []" question or to the
array performance, I dared to move it to a new thread.

Gecko takes undefined value strictly as per Book 4, Chapter 3, Song 9
of Books of ECMA

(Paragraph 4.3.9 of ECMAScript Language Specification, 3rd edition)


<quote> The undefined value is a primitive value used when a variable
has not been assigned a value. </quote>

As a matter complication JavaScript is the only language I know where
one can write:
var foo = undefined;
which is - strictly speaking - "keep foo but assign it the value that
foo was not assigned and never existed" which is - even more strictly
speaking - totally meaningless.

In case of an elision in an array initializer you *do* assign values to
each and every array member (Mr. Cornford would say something like
"[[Put]] method is called for each evaluation result").

This way
var arr = ['A',,'B']
really means
var arr = ['A',undefined,'B']
with three array members explicetly assigned to the array on the
initialization stage. And each and every *assigned* array member is
reflected as an enumerable object property of the underlaying Object
object. To see the difference (and the real sense of undefined value)
try this:

<script type="text/javascript">
function f(arg) {
for (var p in arg) {
window.alert(arg[p] || 'undefined');
}
window.alert('loops: ' + i);
}

function demo() {
var arr = ['A',,'B'];
arr[100] = 'C';
f(arr);
}

window.onload = demo;
</script>

arr[1] member gets an explicit assignment; thus then you treat your
array as an Object type, you see it as property "1" with value
undefined.
After arr[100] = 'C'; you're getting 96 members gap to the next defined
value. But arr[3]...arr[99] never participated in any assignment
operations. They are undefined and existing only in the abstract array
continuum space. Therefore they are not reflected as object properties.

 
Reply With Quote
 
 
 
 
Richard Cornford
Guest
Posts: n/a
 
      09-09-2006
VK wrote:
> (see the post by ASM in the original thread; can be seen at
>

<http://groups.google.com/group/comp....e_frm/thread/3
716384d8bfa1b0b>
> as an option)
>
> As that is not in relevance to "new Array() vs []" question
> or to the array performance, I dared to move it to a new thread.


Or was it because you might avoid looking as much of a fool if you post
this without a context as you would if you did.

> Gecko takes undefined value strictly as per Book 4, Chapter 3,
> Song 9 of Books of ECMA
>
> (Paragraph 4.3.9 of ECMAScript Language Specification, 3rd edition)
>


The numbering of clauses in ECMA 262 has no relationship to paragraphs,
books, chapters or songs.

> <quote> The undefined value is a primitive value used when
> a variable has not been assigned a value. </quote>


And section 10.1.3 explains the assignment of the undefined value to
instantiated variables. And no observable behaviour of _any_ ECMAScript
implementations contradicts section 10.1.3.

> As a matter complication JavaScript is the only language I
> know where one can write:
> var foo = undefined;


The only thing specific to javascript in that statement is using - var -
to declare a variable (and that may not be unique to javascript).

> which is - strictly speaking - "keep foo but assign it the
> value that foo was not assigned and never existed"


Nonsense. The meaning of that statement is in two parts:-

1. During 'variable instantiation' for the execution context; create
a property named 'foo' on the Activation/Variable object for the
execution context (with a DontDelete attribute) and assign the
Undefined value to it.

2. When execution of the code arrives at the assignment expression:
The left-hand side is evaluated (into a Reference type with
the Activation/Variable object as its 'base' property and 'foo'
as its property name). The right hand side is evaluated to a
value:
The Identifier 'undefined' is resolved against the scope chain
to give a Reference type. ECMAScript Edition 3 introduced a
property of the global object with the name 'undefined' set to
the Undefined value so the Reference type will likely have the
global object as its 'base' property. In pre-ECMAScript edition
3 environments that do not have a global 'undefined' property
as an extension, or no programmer defined alternative has been
created, the 'base' property of the Reference type will be null.

The resulting Reference type is then passed to the internal
GetValue function to recover a value (and exception will be
thrown at this point if the Reference type has a null 'base'
property).

The value of the right hand side is then used with the Reference
type from the left hand side in order to assign the value. The
property of the Activation/Variable object named 'foo' is
assigned the value of the right hand side (assuming no exception
was thrown while recovering the value from the Identifier
- undefined -).

> which is - even more strictly
> speaking - totally meaningless.


What you wrote is meaningless, but that is just a manifestation of your
not understanding javascript. The actual statement is doing nor more
than (and no less than) evaluating a variable (undefined) and assigning
its value to another variable (foo).

> In case of an elision in an array initializer you *do* assign
> values to each and every array member


Rubbish. The evaluation of an elision will not result in any value being
assigned to any element of an array except its - length - property in
the event that the elision is not followed by an AssignmentExpression.

> (Mr. Cornford would say something like
> "[[Put]] method is called for each evaluation result").


I am unlikely to say something that is utterly false.

> This way
> var arr = ['A',,'B']
> really means
> var arr = ['A',undefined,'B']


No it does not. It is closer to:-

var arr = new Array;
arr[0] = 'A';;
arr[2] = 'B';

> with three array members explicetly assigned to the array
> on the initialization stage.


If that did happen it would be an implementation bug (as was the case in
the firefox/Mozilla versions discussed in the other thread).

> And each and every *assigned* array member is
> reflected as an enumerable object property of the
> underlaying Object object. To see the difference (and the
> real sense of undefined value) try this:
>
> <script type="text/javascript">
> function f(arg) {
> for (var p in arg) {
> window.alert(arg[p] || 'undefined');
> }
> window.alert('loops: ' + i);
> }
>
> function demo() {
> var arr = ['A',,'B'];
> arr[100] = 'C';
> f(arr);
> }
>
> window.onload = demo;
> </script>
>
> arr[1] member gets an explicit assignment;


If it does then that would be in implementation bug.

> thus then you treat your array as an Object type,


There is no meaningful sense in which anyone could treat an array as not
being an object type, as it always is of that type.

> you see it as property "1" with value
> undefined.
> After arr[100] = 'C'; you're getting 96 members gap to
> the next defined value. But arr[3]...arr[99] never participated
> in any assignment operations. They are undefined and existing
> only in the abstract array continuum space. Therefore they are
> not reflected as object properties.


So, apart from demonstrating your ability to shamelessly post material
that is 100% factually false (that is; your assertions here about what
ECMA 262 3rd Ed. says and means are the opposite of reality) what is
your point?

At lest the other thread came to the (correct) conclusion that the
firefox/Mozilla behaviour described was an implementation bug.

Richard.


 
Reply With Quote
 
 
 
 
VK
Guest
Posts: n/a
 
      09-09-2006

Richard Cornford wrote:
> At lest the other thread came to the (correct) conclusion that the
> firefox/Mozilla behaviour described was an implementation bug.


I will definitely clarify this on Bugzilla and post the response here.
Nevertheless in the matter of JavaScript engine behavior Mozilla is
most likely to be by ECMAScript standard, at least it was since the
beginning and until now.

Before Mozilla team will give an answer, I say my humble opinion on
this matter: it is another side effect of specification bug
allowing undefined value to be *assigned* and being involved in some
internal *assignment* operations.

I'm glad that I don't need to make a choice how to treat a property
with explicetly assigned value "this property doesn't exist and never
existed".
As a property with such value? (Gecko)
As non-existing property? (IE and Co)

Truthfully I would feel like to drop a coin, and then go to Switzerland
to hit some dumb heads

 
Reply With Quote
 
John G Harris
Guest
Posts: n/a
 
      09-09-2006
In article <(E-Mail Removed) .com>, VK
<(E-Mail Removed)> writes

<snip>
>As a matter complication JavaScript is the only language I know where
>one can write:
> var foo = undefined;
>which is - strictly speaking - "keep foo but assign it the value that
>foo was not assigned and never existed" which is - even more strictly
>speaking - totally meaningless.

<snip>

'Undefined' is a short way of saying the value it had when it was
created and hadn't yet been assigned any different value. Assigning
'undefined' (a keyword) is a way of restoring it to the initial state.

I'm amazed that VK has the nerve to complain about a slightly awkward
use of English.

John
--
John Harris
 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      09-09-2006
VK wrote:
> Richard Cornford wrote:
>> At lest the other thread came to the (correct) conclusion
>> that the firefox/Mozilla behaviour described was an
>> implementation bug.

>
> I will definitely clarify this on Bugzilla and post the
> response here.


Why, when the tread you decided your post should not be added to already
includes the bugzilla report (with its confirmation that it was a bug)?

> Nevertheless in the matter of JavaScript engine behavior
> Mozilla is most likely to be by ECMAScript standard, at
> least it was since the beginning and until now.


Not really. There are very few actual implementation bugs and those few
are pretty evenly distributed.

> Before Mozilla team will give an answer,


Too late then.

> I say my humble opinion on this matter:


Nobody cares what your opinion is.

> it is another side effect of specification bug


Half-wit.

> allowing undefined value to be *assigned* and being
> involved in some internal *assignment* operations.


Your inability to understand javascript is well established by now, but
as a consistent, logical system with its behaviour fully specified (so
completely understandable and predictable) that inability is a
reflection only on your mental processes and nothing else.

> I'm glad that I don't need to make a choice how to
> treat a property with explicetly assigned value "this
> property doesn't exist and never existed".


That is the sort of nonsense that makes it clear why your opi9nion is of
no value.

> As a property with such value? (Gecko)
> As non-existing property? (IE and Co)
>
> Truthfully I would feel like to drop a coin, and then go to
> Switzerland to hit some dumb heads


The specification is clear on the subject, Mozilla/Gecko is (or was)
wrong and will be fixed so that it complies with the specification.

Richard.


 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      09-09-2006
John G Harris wrote:
<snip>
> ... . Assigning 'undefined' (a keyword)


Not a keyword, just an Identifier, and one that is likely to be resolved
as the specification defined (ECMA 262 3re Ed. Section 15.1.1.3)
property of the global object, which explicitly has the Undefined value.
As it is not a keyword any function, formal parameter or variable could
be named 'undefined' (along with any custom object property) and so
replace or mask the global object's property. (The global 'undefined'
property has the DontDelete and DontEnum attributes but it is not
ReadOnly). Though obviously 'undefined' would be a spectacularly poor
name to be giving to functions/parameters/variables/properties.

<snip>
> I'm amazed that VK has the nerve ...


Ditto.

Richard.


 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      09-09-2006
> > I will definitely clarify this on Bugzilla and post the
> > response here.

>
> Why, when the tread you decided your post should not be added to already
> includes the bugzilla report (with its confirmation that it was a bug)?


At the moment I was starting this thread the latest post by Cameron
McCormack
<http://groups.google.com/group/comp.lang.javascript/msg/45a87b8f172b03b4>
was not shown yet in my browser. The thread ended up by Rob's post.

I'm gratiful to Cameron McCormack for finding the relevant Bugzilla
filing and for saving my time on that. So indeed it is confirmed to be
a Gecko JavaScript engine bug: see
<https://bugzilla.mozilla.org/show_bug.cgi?id=260106>
So I was wrong and Microsoft was right in this case.

Yet this bug existence (if translated from C++) is layed on the
situation of an "assignment of the value of no assignment" and
indexing troubles after that. Doesn't make myself neither Mozilla right
of course.

 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      09-09-2006
VK wrote:
<snip>
> So I was wrong

<snip>

That was inevitable from the moment you posted. It is just a pity you
waste so much time (that could be better given to more deserving cases)
finding out why you were inevitably wrong. Just understand; you
conception of javascript is largely a fictional product of your own
deranged imagination and has no more than a superficial relationship
with reality. If you would finally accept that truth you might be able
to do something about acquiring a worthwhile understanding of the
subject, or at leas to stop wasting so much of other peoples time by
keeping your lunacy to yourself.

Richard.


 
Reply With Quote
 
scriptguru@gmail.com
Guest
Posts: n/a
 
      09-09-2006
Richard,
it looks like there are only morons surrounding you.
Maybe you are too perfect for this world? ;o)

 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      09-10-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Richard,
> it looks like there are only morons surrounding you.
> Maybe you are too perfect for this world? ;o)


What is up, you have something against the propagation of accurate
information?

Richard.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript new-new-new-new-newbee weblinkunlimited@gmail.com Javascript 2 03-11-2008 01:15 AM
New to C, "Undefined reference's" steve C Programming 5 12-02-2007 01:20 PM
typeof x == 'undefined' or x == undefined? -Lost Javascript 13 01-31-2007 12:04 AM
operators (f.e. new[]) undefined Florian Xaver C++ 2 08-09-2005 02:32 PM
undefined behavior or not undefined behavior? That is the question Mantorok Redgormor C Programming 70 02-17-2004 02:46 PM



Advertisments