Take a look at this cut off code:
main = function() {
alert('This is ' + T);
}
caller = function() {
var T = 'me';
main();
}
caller();
as you can see, I want the main function to determine the value of the variable T, but the browser shows this error: T - undefined.
I can handle this error by changing the scope of the T variable to the global scope, or even pass the T variable to main, but for some reason I don’t want to use it, and I want to declare the T variable in the scope of the main function. Is this possible or not? How can I handle this scenario?
Thanks.
source
share