
Consider the aftercited JavaScript skeletal program: //the ocean program var X: office sub1 () { var x: office sub2() { … } } office sub3 () { … } Pretend the action of this program is in the aftercited ace order: ocean calls sub1 sub1 calls sub2 sub2 calls sub3 a. Assuming static scoping, which avowal of x is the rectify individual control a relation to x in: i. sub1 ii. sub2 iii. sub3 b. Repeat sunder a, barring pretend dynamic scoping. Pretend the aftercited JavaScript program was interpreted using static-scoping rules. What appreciate of x is displayed in office sub1? Under dynamic scoping rules, what appreciate of x is displayed in office sub1? var X office sub1() { muniment.transcribe (“x = ” + x + ” “): } office sub2 () { var x: x = 10: sub1(): } x = 5: sub2 ();
1.)
a.) sub1
When it is control static scoping the appreciate of the substituteable x conciliate reocean identical or contant and hence, refernecing conciliate beseem practice hazard easier than what it is when the ocean calls sub1.
b.) sub2
When it is control the dynamic scoping the appreciate of the substituteable x conciliate substitute as quickly as the leading relations are started on the attached height declaration.
Hence, these are the fact referncing of the substituteable x and where should it be placed.
2.) The appreciate of the x conciliate be refernced 10 as it is in dynamic scoping consequently once the office reaches to the contiguous office it conciliate substitute and the appreciate is reflected as 10 at his conclusive tidings.