From: Antony Scriven on
On Mar 10, 11:53am, Jorge wrote:

> [...]
>
> var el= myarray[n];
> if (n>= myarray.length) {
>
> //myarray[n] does not exist
> //e.g. [1,2,,3][27]
>
> } else if (!(n in myarray)) {
>
> //myarray[n] is a hole
> //e.g. [1,2,,3][2]
>
> } else if ((el === undefined) || (el === null)) {
>
> //exists, but its value is undefined or null
> //e.g. [1,2,undefined,3][2] or [1,2,null,3][2]}

What exactly do you mean by 'exists'? If I do

var myarray = new Array(5);

does a[3] exist? --Antony
From: David Mark on
Antony Scriven wrote:
> On Mar 10, 11:53am, Jorge wrote:
>
> > [...]
> >
> > var el= myarray[n];
> > if (n>= myarray.length) {
> >
> > //myarray[n] does not exist
> > //e.g. [1,2,,3][27]
> >
> > } else if (!(n in myarray)) {
> >
> > //myarray[n] is a hole
> > //e.g. [1,2,,3][2]
> >
> > } else if ((el === undefined) || (el === null)) {
> >
> > //exists, but its value is undefined or null
> > //e.g. [1,2,undefined,3][2] or [1,2,null,3][2]}
>
> What exactly do you mean by 'exists'? If I do

The property (2 in the "hole" example) does not exist (but 0, 1 and 3 do).

>
> var myarray = new Array(5);
>
> does a[3] exist? --Antony

No (and neither do the 0, 1, 2 or 4 properties).
From: Jorge on
On Mar 10, 3:00 pm, Antony Scriven <adscri...(a)gmail.com> wrote:
> On Mar 10, 11:53am, Jorge wrote:
>
>  > [...]
>  >
>  > var el= myarray[n];
>  > if (n>= myarray.length) {
>  >
>  >  //myarray[n] does not exist
>  >  //e.g. [1,2,,3][27]
>  >
>  > } else if (!(n in myarray)) {
>  >
>  >  //myarray[n] is a hole
>  >  //e.g. [1,2,,3][2]
>  >
>  > } else if ((el === undefined) || (el === null)) {
>  >
>  >  //exists, but its value is undefined or null
>  >  //e.g. [1,2,undefined,3][2] or [1,2,null,3][2]}
>
> What exactly do you mean by 'exists'? If I do
>
>    var myarray = new Array(5);
>
> does a[3] exist?

(I guess you meant myarray[3], right ?)

No, (3 in myarray) would return false. Call it a hole -if you want-
but it's not the same as if you did:

myarray[3]= undefined;
3 in myarray; //now it exists
--> true
delete myarray[3]; //creates a "hole" @ index #3
3 in myarray;
--> false
--
Jorge.
From: Antony Scriven on
On Mar 10, 2:13pm, Jorge wrote:

> On Mar 10, 3:00pm, Antony Scriven <adscri...(a)gmail.com> wrote:
>
> > On Mar 10, 11:53am, Jorge wrote:
>
> > > [...]
> > >
> > > var el= myarray[n];
> > > if (n>= myarray.length) {
> > >
> > > //myarray[n] does not exist
> > > //e.g. [1,2,,3][27]
> > >
> > > } else if (!(n in myarray)) {
> > >
> > > //myarray[n] is a hole
> > > //e.g. [1,2,,3][2]
> > >
> > > } else if ((el === undefined) || (el === null)) {
> > >
> > > //exists, but its value is undefined or null
> > > //e.g. [1,2,undefined,3][2] or [1,2,null,3][2]}
>
> > What exactly do you mean by 'exists'? If I do
>
> > var myarray = new Array(5);
>
> > does a[3] exist?
>
> (I guess you meant myarray[3], right ?)

Ah yes, cognitive typo. :-)

> No, (3 in myarray) would return false. Call it a hole -if
> you want- [...]

Thanks, I see what you're getting at now. The comments in
your code could be taken to suggest that a hole is somehow
different from a nonexistent property. --Antony
From: SAM on
Le 3/10/10 3:00 PM, Antony Scriven a �crit :
> On Mar 10, 11:53am, Jorge wrote:
>
> > [...]
> >
> > var el= myarray[n];
> > if (n>= myarray.length) {
> >
> > //myarray[n] does not exist
> > //e.g. [1,2,,3][27]
> >
> > } else if (!(n in myarray)) {
> >
> > //myarray[n] is a hole
> > //e.g. [1,2,,3][2]
> >
> > } else if ((el === undefined) || (el === null)) {
> >
> > //exists, but its value is undefined or null
> > //e.g. [1,2,undefined,3][2] or [1,2,null,3][2]}
>
> What exactly do you mean by 'exists'? If I do
>
> var myarray = new Array(5);

When you do that you create an empty array
(an array whom elements do not exist)

> does a[3] exist? --Antony

Yes I think we almost could say so (its place is created)
but it has no value, it's *not known*, it's "undefined".

and a[6] too !

All what you have to know is that in JS a no present (or not existing)
element is undefined (it has not be defined, created).

A null element (or object) is an element ... null.

--
sm