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

1. Consider the following JavaScript program (6pts) vaX, y, Z; function sub1 { v

ID: 3730401 • Letter: 1

Question

1. Consider the following JavaScript program (6pts) vaX, y, Z; function sub1 { var.a, y, Z, function sub2 ( var a, b, z; function sub3 (X 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 scope 2. Show the order of evaluation of the expressions assuming that there are no precedence rules and all operators associate right to left. (9 pts) a*b-1 + c ii)(a-b)/c & (d'ela-3) ii) a (b-1) /c mod d 3. Let the function fun be defined as (10 pts) int fun(int *k) *k +4; return 3* ("k) -1;) suppose fun is used in the program as follows void maiolX intL:10, j = 10, sum1, sum2; sum1- (i/2) + fun (&i;); sum2 - fun (&j;) + (j/ 2);) What are the values of sum1 and sum2 a. Operands in the expressions are evaluated left to right? b. Operands in the expressions are evaluated right to left?

Explanation / Answer

ANswer:

As per Chegg Policy Only First Answer written.

Please letme know ..If you have any quiries.

1. var x,y,z ; //Global Variable declaration.   
2. function sub1()
3. {
4. var a,y,z; //Variables of sub1
5.   
6. function sub2()
7. {
8. var a,b,z; //variables of sub2
9.   
10. }   
11. }
12. function sub3()
13. {
14. var a,x,w; //variables of sub3
15.   
16. }

Here We have Global Variables and Local Variables.
Global variables have there scope throughout the Program.
It means We can use those global variables at any sub program or any sub block.
But In case of Ambiguity. First pririty should be given to Local Variables.


At line one x,y,x are defined those have scope throughout the complete Program.
At line 4 a,y,z are defined. They have scope throughout the sub1
which is 3 to 11. But In case of ambiguity at sub2. sub1 variableshave less priority than a,b,z
those are created at line 8(sub2 variable).


at Line 8. a,b,z are defined. They have scope in sub2 block.
In this block they have pririty than the global and sub1 variables.
sub3 variable are not valid here.

a,x,w are defined in sub3. They have scope upto sub3 only.
These variables have high priority than the Global variables.
sub1 and sub2 variables are not valid here.