harshpandya Posted March 5, 2008 Share Posted March 5, 2008 var a;Function f(){g();Var a = 10;}function g(){var x = a;}Ok My question is I want to use variable "a" value in function g() and assign to x. Its not working for me Why ?????????????thanks, Link to comment Share on other sites More sharing options...
jesh Posted March 5, 2008 Share Posted March 5, 2008 Looks like a problem with variable scope. Try this: var a = 0;function f(){ g(); a = 10;}function g(){ var x = a; alert(x);}f(); // makes g alert "0";f(); // makes g alert "10"; You may want to read up on variable scope:http://www.google.com/search?q=javascript+variable+scope Link to comment Share on other sites More sharing options...
jhecht Posted March 5, 2008 Share Posted March 5, 2008 function f(){ var a = 10; g(a);}function g(x){ alert(x);} should output "10" in an alert box. Link to comment Share on other sites More sharing options...
harshpandya Posted March 5, 2008 Author Share Posted March 5, 2008 function f(){ var a = 10; g(a);}function g(x){ alert(x);} should output "10" in an alert box. Thanks I used this one and it worked cool Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.