Page 1 of 1

[SOLVED]Variable set or not?

Posted: Sun Oct 07, 2007 1:08 am
by figaro11
How do I check if a variable has been defined or set?

I use:

Code: Select all

if (variable === undefined)
{
//it doesn't exist
}
But of course a variable has to be defined in order to check if a defined variable is undefined... So how do I check if a variable exists?

EDIT:

Nevermind, I got it.

Code: Select all

if (typeof variable == "undefined")
{
//it doesn't exist
}

Posted: Sun Oct 07, 2007 2:45 am
by Christopher
Take a look at isset()

Posted: Sun Oct 07, 2007 4:15 am
by VladSun
@arborint: Javascript ;)

There is a nice discussion in : http://jehiah.cz/archive/javascript-isdefined-function