Question

Consider the following JavaScript program: var x, y, z; function sub1() { var a, y, z;...

Consider the following JavaScript program:


var x, y, z;
function sub1() {
var a, y, z;
function sub2() {
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.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hi there,

If you still have any queries,feel free to ask in the comments box.

The variables x,y,z are global scope,so they can be used anywhere in the program units they are visible to all the bodies.

In sub1()

The variables visible are a,x,y,z.a is the local variable of that block it is visible only in that block.The redeclaration of y,z indicates that whatever new value of y,z be given in this block,it is updated globally.

In sub2()

The variables visible are a,b,x,y,z.a,b are the local variables of that block,it is visible only in that block.The redeclaration of y,z indicates that whatever new value of y,z be given in this block,it is updated globally.

In sub3()

The variables visible are a,w,x,y,z.a,w are the local variables of that block,it is visible only in that block.The redeclaration of x indicates that whatever new value of x be given in this block,it is updated globally.

Add a comment
Know the answer?
Add Answer to:
Consider the following JavaScript program: var x, y, z; function sub1() { var a, y, z;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT