Click to See Complete Forum and Search --> : stupid javascript question...


mitya
12-12-2003, 05:37 AM
Silly me, thinking I could expect JS to be syntactically identical to PHP. How do I check if a var is null or hasn't been set?? In PHP this would simply be:

if (!$var) { or if (!isset($var)) {

But if I do either of them in JS, or even if (var = null), it moans that the var is undefined. Which, er, is what I'm wanting to check.

Silly JS! (thanks in advance)

olaf
12-12-2003, 05:41 AM
Hi,

i have learned that:

null = no var
"" = empty var
0 = var is 0

I think thats all...

I have also problems as php developer with the DOM...

Gollum
12-12-2003, 05:42 AM
In fact...

if ( v == null ) // v is null (no relli)

if ( v == undefined ) // v has not been set

mitya
12-12-2003, 05:45 AM
I'm aware of the different values a var can have, i.e. "" and 0 are values whereas null is not etc. But the problem seems to be that if I want to check the status of a var that hasn't been set yet, it moans that, er, it hasn't been set yet!!

You can't beat a nice bit of logic.