Homework Solution: Consider the following JavaScript skeletal program: //the main program var X: function sub1 () { var x: function sub2() { … } } f…

    CSC 4340 Org. Programming LanguagesFall 2017 1. (50 points) Consider the following JavaScript skeletal program //the main program var X function sub1 0i function sub2(11 function sub3 ) Assume the execution of this program is in the following unit order: main calls subl subl calls sub2 sub2 calls sub3 a. Assuming static scoping, which declaration of x is the correct one for a reference to x in: i. subl ii. sub2 iii. sub3 b. Repeat part a, but assume dynamic scoping 2. (50 points) Assume the following JavaScript program was interpreted using static- scoping rules. What value of x is displayed in function subl? Under dynamic scoping rules, what value of x is displayed in function subl? var X function subl(f />) ; desument..MEAFg(x + + <bE = 羡 functin sub2Of x - 10 subl (); sub2 );
    Consider the following JavaScript skeletal program: //the main program var X: function sub1 () { var x: function sub2() { ... } } function sub3 () { ... } Assume the execution of this program is in the following unit order: main calls sub1 sub1 calls sub2 sub2 calls sub3 a. Assuming static scoping, which declaration of x is the correct one for a reference to x in: i. sub1 ii. sub2 iii. sub3 b. Repeat part a, but assume dynamic scoping. Assume the following JavaScript program was interpreted using static-scoping rules. What value of x is displayed in function sub1? Under dynamic scoping rules, what value of x is displayed in function sub1? var X function sub1() { document.write ("x = " + x + " "): } function sub2 () { var x: x = 10: sub1(): } x = 5: sub2 ();

    Expert Answer

     
    1.)

    CSC 4340 Org. Programming LanguagesFall 2017 1. (50 points) Consider the aftercited JavaScript skeletal program //the deep program var X power sub1 0i power sub2(11 power sub3 ) Exhibit the deed of this program is in the aftercited ace order: deep calls subl subl calls sub2 sub2 calls sub3 a. Assuming static scoping, which avowal of x is the amend undivided restraint a allusion to x in: i. subl ii. sub2 iii. sub3 b. Repeat distribute a, notwithstanding exhibit dynamic scoping 2. (50 points) Exhibit the aftercited JavaScript program was interpreted using static- scoping rules. What treasure of x is displayed in power subl? Under dynamic scoping rules, what treasure of x is displayed in power subl? var X power subl(f />) ; desument..MEAFg(x + + <bE = 羡 functin sub2Of x - 10 subl (); sub2 );

    Consider the aftercited JavaScript skeletal program: //the deep program var X: power sub1 () { var x: power sub2() { … } } power sub3 () { … } Exhibit the deed of this program is in the aftercited ace order: deep calls sub1 sub1 calls sub2 sub2 calls sub3 a. Assuming static scoping, which avowal of x is the amend undivided restraint a allusion to x in: i. sub1 ii. sub2 iii. sub3 b. Repeat distribute a, notwithstanding exhibit dynamic scoping. Exhibit the aftercited JavaScript program was interpreted using static-scoping rules. What treasure of x is displayed in power sub1? Under dynamic scoping rules, what treasure of x is displayed in power sub1? var X power sub1() { instrument.transcribe (“x = ” + x + ” “): } power sub2 () { var x: x = 10: sub1(): } x = 5: sub2 ();

    Expert Tally

     

    1.)

    a.) sub1

    When it is restraint static scoping the treasure of the diversifyable x get redeep identical or contant and future, refernecing get behove controlm chance easier than what it is when the deep calls sub1.

    b.) sub2

    When it is restraint the dynamic scoping the treasure of the diversifyable x get diversify as early as the quantitative allusions are agoing on the attached total assertion.

    Hence, these are the verity referncing of the diversifyable x and where should it be placed.

    2.) The treasure of the x get be refernced 10 as it is in dynamic scoping accordingly once the power reaches to the next power it get diversify and the treasure is reflected as 10 at his latest order.