« Wacky instance variable initialization | Main | WSDL download failed for the following URLs: »

May 06, 2004

When null is not quite null

Well maybe this is obvious to you but it threw me for a while.

Lets say you have an object and you want to check whether it is null...

trace(x==null)

and this shows true.

Its clear that the object x is empty and contains nothing isn't it.

Well actually no.

If x just happens to be an attributes array from an XMLNode it so happens that it will be equal to null and at the same time can contain values...

var x= node.attributes
trace(x==null) // display true
trace(x.age) //displays a valid value for an assigned age attribute..

So does this mean there is no way of finding out if the attributes array is empty without looping over all the attributes with a for(x in attributes) type of check?

Comments

Will ultra-strict equality work? I'm under the assumption that the "===" operation is strict to all parts, as if you do a for...in loop on the element.

trace(x===null)

Haven't tried it yet though

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)