Consider the following skeletal and JavaScript-like program: function main() { var a, b, w, d; function sub1() { var a, c, w, v; function sub2() { var a, d; } ... } function sub3() { var x, w, v, d; .... } } 4.1. (4 points) List all the variables, along with the program units (sub1, sub2, sub3, or main) where they are declared, that are visible in the body of sub3, assuming that static scoping is used. 4.2. (4 points) List all the variables, along with the program units (sub1, sub2, sub3, or main) where they are declared, that are visible in the body of sub2, assuming that static scoping is used.

Respuesta :

Answer:

A. Sub3 local variables are; x, w, v and d while the visible variables from the main variables; a and b.

B. Sub2 local variables are; a and d while the visible variables from the main and sub1 are; c, b, w and v

Explanation:

The variable name defined with the 'var' in the main is on a global scope to other functions defined in it. But when the same name of the variable is defined in the inner functions, its variable name is overridden with the newly defined variable.