Ask Question
3 January, 06:12

Assume the following jа vascript 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 ();

+3
Answers (1)
  1. 3 January, 09:39
    0
    The value of x in both scope can be described as follows:

    i) Static scope:

    x = 5

    ii) Dynamic scope:

    x=10

    Explanation:

    The static scoping is also known as an arrangement, which is used in several language, that defines the variable scope like the variable could be labelled inside the source that it is specified.

    i) program:

    function sub1 () / /defining function sub1

    {

    print ("x = " + x + ""); / /print value

    }

    function sub2 () / /defining function sub2

    {

    var x; / /defining variable x

    x = 10; / /assign value in variable x

    sub1 (); / /caling the function sub1

    }

    x = 5; / /assign the value in variable x

    sub2 (); / /call the function sub2

    In Dynamic scoping, this model is don't see, it is a syntactic mode that provides the framework, which is used in several program. It doesn't care how well the code has been written but where it runs.

    ii) Program:

    var x / /defining variable x

    function sub1 () / /defining a function sub1

    {

    print ("x = " + x + ""); / /print the value of x

    }

    x = 10; / / assign a value in variable x

    sub2 (); / / call the function sub2

    function sub2 () / /defining function sub2

    {

    var x; / /defining variable x

    x = 5; / / assign value in x

    sub1 (); //call the function sub1

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Assume the following jа vascript program was interpreted using static-scoping rules. What value of x is displayed in function sub1? ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers