8 Consider the following JavaScript program var x y z functi
8. Consider the following JavaScript program: var x, y, z; function sub1() { var a, y, z; function sub2() { var a, b, z; . . . } . . . } function sub3() { var a, x, w; . . . } List all the variables, along with the program units where they are declared, that are visible in the bodies of sub1, sub2, and sub3, assuming static scoping is used.
Solution
Assuming that static scoping is used, following are the variables:
sub1:a(sub1),y(sub1),z(sub1),x(main)
sub2:a(sub2),b(sub2),z(sub2),y(sub1),x(main) (y(sub1) may not be mentioned here since it is noy visbile.However, it is mentioned her to specify its presence)
sub3:a(sub3),x(sub3),w(sub3),y(main),z(main)
