[SOLVED]Variable set or not?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
figaro11
Forum Commoner
Posts: 64
Joined: Mon Sep 17, 2007 11:49 pm

[SOLVED]Variable set or not?

Post 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
}
Last edited by figaro11 on Sun Oct 07, 2007 3:02 am, edited 1 time in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Take a look at isset()
(#10850)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

@arborint: Javascript ;)

There is a nice discussion in : http://jehiah.cz/archive/javascript-isdefined-function
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply