Subj : Re: undefined values To : Matthias Thiel From : Brendan Eich Date : Mon Aug 04 2003 09:54 pm Matthias Thiel wrote: > Hi, > > is there a possibility to check, whether a variable is defined or not > (using SpiderMonkey) ? > I tried out scripts like "x==undefined", but I got an error instead of true or false. > With Rhino, such scripts are working and returning true or false. Is it a feature of Rhino ? > I have no idea why that would work in Rhino -- perhaps you are not checking for an error exception? You can test whether x identifies a property in an object o (or in an object on its prototype chain) via the 'in' operator: if ('x' in o) print('x identifies a property in o with value ' + uneval(o.x)); If you want to test whether a variable property identifier names a property in o, you would generalize the above like so: var v = 'x'; if (v in o) { printf(v + ' identifies a property in o with value ' + uneval(o[v])); } /be .