Question

Write down your solution for this assignment, take a picture and submit on canvas. Typed answers...

Write down your solution for this assignment, take a picture and submit on canvas. Typed answers are not graded.

  1. Given the following code, write down the execution steps of each line along with changes in variables, and what will be printed out after execution of each line. Make sure to identify the caller and callee functions and processes. If you are not sure how this is done, run this code in a browser console, and set a breakpoint at the beginning of the code, then step through the code line by line.
  • If there will be a missing step, you will not get anypoint.
  • This exercise is crucial for your understanding of the javascript execution environment as we are going to us JS heavily for the rest of the semester.

var globalVar =1;

function foo(argVar){

var localVar=2;

return function(arg){

argVar +=arg;

localVar += arg;

globalVar += arg;

console.log('F', argVar, localVar, globalVar);

  

};

}

var func1 = foo(1);

var func10 = foo(10);

func1(1);

func10(2);

console.log('G', globalVar);


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

OUTPUT:

"F" 2 3 2

"F" 12 4 4

"G" 4

EXPLAINATION:

var func1= foo(1)

foo(1)

local var=2

fun(1)

argvar+=arg (1+1=2) :argvar =2

localvar+=arg (2+1) : localvar=3

globalvar+=arg (1+1) : globalvar=2

fun(10)

10+2=12 (because localvar is 2 so arg change into 2)

2+2=4

2+2=4

func1(1); //will not execute

func10(2); //will not execute

console.log('G', globalVar);

4

Add a comment
Know the answer?
Add Answer to:
Write down your solution for this assignment, take a picture and submit on canvas. Typed answers...
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
  • Write a WebGL program that displays a rotating pendulum. The pendulum bob is free to rotate...

    Write a WebGL program that displays a rotating pendulum. The pendulum bob is free to rotate through 360 degrees about an anchor point at the center of the canvas. The pendulum has the following three components. 1) The anchor point is a green square centered at the origin (0,0) with point size = 5 pixels. 2) The bob is a blue hexagon of radius r = 0.1. Render this with a triangle fan centered at the origin (along with a...

  • Assignment Overview In Part 1 of this assignment, you will write a main program and several...

    Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...

  • Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin...

    Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin at the University of Washington, Seattle, who originally wrote this assignment (for their CSE 142, in Java) This program focuses on classes and objects. Turn in two files named Birthday.cs and Date.cs. You will also need the support file Date.dll; it is contained in the starter project for this assignment. The assignment has two parts: a client program that uses Date objects, and a...

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
ADVERTISEMENT