Below code, I need to access variable a inside call function
$(document).ready(function(){
var a=10;
call("a");
function call(x) {
//alert 10 using x
}
});
Please dont change the code, just write the correct alert statement
Below code, I need to access variable a inside call function
$(document).ready(function(){
var a=10;
call("a");
function call(x) {
//alert 10 using x
}
});
Please dont change the code, just write the correct alert statement
Try to do like this,
$(document).ready(function(){
var a=10;
call(a);
function call(x) {
alert(x);
}
});
In your code you are passing the variable as a string. so it won't do the things as are expecting. You may use eval()
for this purpose, that is reading a value from the string formatted variable name. But it is not a recommended one since it is modifying the scope at runtime.