--- In flexcoders@yahoogroups.com, "Tracy Spratt" <tr...@...> wrote: > > _____ > > From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On > Behalf Of Paul Andrews > Sent: Wednesday, August 12, 2009 9:33 PM > To: flexcoders@yahoogroups.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.