Sunday, August 2, 2009

I had declared a variable as global in javascript..how can i access that var in a function.?

here the brief xplanation of my question :





var a; // which is declared as global var


function x()


{


a=10;


}


function y()


{


b=50;


c=a+b; //in this function i have to access variable a,,


}





tell me how can i access which i wrote program in javascript..


i want xplanation with correct syntax..plz reply me.

I had declared a variable as global in javascript..how can i access that var in a function.?
Make the function take a parameter. For example,


var a;


function x(a)


{


a=10;


}


function y(a)


{


b=50;


c=a+b; //in this function i have to access variable a,,


}


//then call the function with the parameter:


function x(a);


function y(a);





If you need more access to global variables, use commas to seperate the parameters, like:


FunctionX(a,b,c,d)


{


a=b=c=d;


}


No comments:

Post a Comment