Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3. Assume the following JavaScript program was interpreted using static-scoping

ID: 3728014 • Letter: 3

Question

3. Assume the following JavaScript program was interpreted using static-scoping rules. What value of x is displayed in function sub1? [20 pts] var x; function sub1){ document.writer>h function sub20 0 var x; x=10; sub10; x = 5; sub2(); 4. Consider the following JavaScript program: var x, y, z; function sub10 var a, y, Z; function sub20 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. [30 pts]

Explanation / Answer

Q:3

The output will be x = 5 because the code is not passing the value 10 to the function sub1 and the value of the global variable is used to print the answer.

Q:4

var x, y, z;

// These variables can be accessed in sub1, sub2 and sub3

function sub1(){

var a, y, z;

// These variables can be accessed in sub1 and sub2

function sub2(){

var a, b, z;

// These three variables can be accessed in sub2 only

}

}

function sub3(){

var a, x, w;// These variable can only be accessed in Sub 3

}

**Comment for any further queries.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote