consider the following JavaScript skeletal program the main
consider the following JavaScript skeletal program
//the main program
var x
function sub1 (){
var x;
function sub2(){
......
}
}
function sub3(){
.....
}
assume that the execution of this progam is in the following unit order:
main call sub1
sub1 calls sub2
sub2 calls sub3
a. Assume static scoping, in the following, which declaration of x is the correct one for a reference to x ?
1. sub1
2. sub2
3. sub3
b. Repeat part a, but assume dynamic scoping.
Solution
1. sub1
In static scoping, a new space for every variable is created which cannot be carried into methods calling from the present method. So, to refer to variable x, it has to be refered through sub1

