Ah, I see something I missed at first. This example is using "literal" xml,
so the null IS getting interpreted by AS as null and not as a string. I bet
it would be different if you did:
var xml:XML = XML("<outer><inner>null</inner></outer>");
Even so I am still surprised because the null should be the text node and
the expression should return an XMLList with zero length. Very interesting.
Tracy Spratt,
Lariat Services, development services available
_____
From: [email protected] [mailto:[email protected]] On
Behalf Of jaywood58
Sent: Thursday, August 13, 2009 12:48 PM
To: [email protected]
Subject: [flexcoders] Re: *** So you think you know ActionScript? (Read
original post first) ***
--- In flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com,
"Tracy Spratt" <tr...@...> wrote:
>
> _____
>
> From: flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com
[mailto:flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com]
On
> Behalf Of Paul Andrews
> Sent: Wednesday, August 12, 2009 9:33 PM
> To: flexcod...@yahoogro <mailto:flexcoders%40yahoogroups.com> ups.com
> Subject: Re: [flexcoders] *** So you think you know ActionScript? (Read
> original post first) ***
>
>
>
>
>
> Dave Glasser wrote:
> > Consider this code snippet:
> >
> > var xml:XML = <outer><inner>null</inner></outer>;
> > var xmlList:XMLList = xml.inner;
> > trace(xmlList == null);
> >
> > What does the trace statement output, true or false, and why?
> >
> > Please provide an answer without running the code (of course) and,
better
> yet, without consulting any documentation, or any of the other answers
that
> may have been posted already (if you read the list in chronological
order.)
> Pretend it's a job interview question and you have to give it your best
shot
> off the top of your head.
> >
> > And also, if you don't mind, don't top-post your answer, so that if
> someone does read your answer before the original post, they might get a
> chance to answer without having seen yours first.
> >
>
> xmlList is set to point at somthing which isn't a list, so I think the
> trace statement will not be reached. That's my 02:31AM thought..
>
>
>
> All e4x expressions return an XMLList. It can be empty but is never a
null.
> Besides, the characters. "null" in a text node are just a string. "null"
in
> an AS comparison is a special value. The trace will display false.
> Trace("xmllist.text() =="null" ); //would return true.
>
>
>
> Tracy Spratt,
>
> Lariat Services, development services available
>
Like Tracy, I thought it would return false, for the same reason -- that
<inner>null</inner> would be interpreted as a string. Was surprised when I
ran the code and saw true. What's going on? It seems like the AS decoder
recognizes "null" as a special case.