Test numeric vbl for null

If a field is numeric (e.g., integer) and can be equal to zero, in a method, is:

if((field_age) && (field_age > 23)) {…

the same as:

if((field_age != null) && (field_age > 23)) { …

…or in the first case will “if(field_age)…” be true when field_age == 0? In my traces, it seems like the latter is the case.

Thank you,
Don

Hi Don,

I think this URL can help you: http://www.mapbender.org/JavaScript_pitfalls:_null,_false,_undefined,_NaN

Don,

The link Michel mentioned is a good helper.

In your 1st example, ‘(field_age)’ will evaluate ‘false’ when the value equals zero or null.
I presume ‘field_age’ is an integer or numeric type column.
If we are talking text field, a value zero will evaluate ‘true’ !

I’d use the 2nd example, which is more safe in any case using numeric type columns.

Hope this helps

Thanks, guys. The concepts of null and undefined are a bit confusing in javascript, particularly in reference to different types of db fields.