How to check a variable defined or not using javascript

by Vinoth 2010-06-05 11:09:33

We can check whether a variable is defined or not in a javascript program


for example take the below ex:

//This part of program is optional
var hi=1;
var page='http://hiox.org';


//This part of program we are going to check whether the variable is declared or not

try{
if(hi){//This line will be execute if variable "hi" defined previously
}
}
catch(err){// If the variable not defined the program will come to this part
var hi=10;
}



I feel its very useful.

Tagged in:

1429
like
0
dislike
0
mail
flag

You must LOGIN to add comments