| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 6 | |
Hi! I would like to know how to distinguish null and undefined values. At first I thought about comparing variables to null and undefined but it seems that these values are same when compared: res = (null == undefined); // res is true! It looks like a bug becouse QScriptValue::toString() returns "null" and "undefined" so these values should not be equal. Regards, -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
Hi,
as far as I remember that is correct behaviour in ECMAScript. The
difference between null and undefined is rather small anyway. If you
want to distinguish between the two types you might want to use the
typeof operator, like this:
if (typeof someVar != 'undefined' && someVar != 'null')
{ // someVar exists and isn't null }
- Thomas
2007/7/30, Rafał Cygnarowski <zswi@xxxxxxx>:
> Hi!
>
> I would like to know how to distinguish null and undefined values. At first I
> thought about comparing variables to null and undefined but it seems that
> these values are same when compared:
>
> res = (null == undefined); // res is true!
>
> It looks like a bug becouse QScriptValue::toString() returns "null"
> and "undefined" so these values should not be equal.
>
> Regards,
> --
> Rafał Cygnarowski
> rafi@xxxxxxx
>
>
Hi, Thomas Dähling wrote: > as far as I remember that is correct behaviour in ECMAScript. The > difference between null and undefined is rather small anyway. If you > want to distinguish between the two types you might want to use the > typeof operator, like this: I think the operator === serves this purpose. Tim ---------------------------------------------------------------------- dr. t. dewhirst [t] +44 (0)131 208 2847 director [w] www.bugless.co.uk bugless software development ltd. -- [ signature omitted ]
Dnia poniedziałek, 30 lipca 2007, Tim Dewhirst napisał: > Hi, > > Thomas Dähling wrote: > > as far as I remember that is correct behaviour in ECMAScript. The > > difference between null and undefined is rather small anyway. If you > > want to distinguish between the two types you might want to use the > > typeof operator, like this: > > I think the operator === serves this purpose. Thank you very much - it solves my problem :) Regards, -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
> as far as I remember that is correct behaviour in ECMAScript. The > difference between null and undefined is rather small anyway. If you That's what I recall aswell. But IIRC they are equal but not identical - so according to ECMAScript "null == undefined" but "null !== undefined". (but I am not 100% sure anymore.) Regards, Malte -- [ signature omitted ]