JavaScript Simplified / Chapter 60 Exercises

  • Index of exercises
  • Email me

1

2

3

4

5

6

7

8

9

10

Congratulations. You've aced all the exercises for this chapter.


To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to CodePen.


Are you ready to rate JavaScript Simplified? on Amazon?


Rate it on Amazon.

0,1,2,3,4,5,6,7,8,9

0

0

0

0

An outer function takes itself out of the picture when it ______ its inner function. returns returns
Given the following code, what string won't display? function outerFunc() {
  let greeting = "Hello";
  function innerFunc() {
    greeting = "G'day";
    console.log(greeting);
  }
  return innerFunc;
}
const aVar = outerFunc();
aVar();
"Hello" •?Hello•?
Given the following code, what is the final value of aVar? function outerFunc() {
  let greeting = "Hello";
  function innerFunc() {
    greeting = "G'day";
    console.log(greeting);
  }
  return innerFunc;
}
const aVar = outerFunc();
aVar();
innerFunc" innerFunc
Fill in the blank to complete the closure. function outerFunc() {
  let greeting = "Hello";
  function innerFunc() {
    greeting = "G'day";
    console.log(greeting);
  }
  _______________
}
const aVar = outerFunc();
aVar();
return innerFunc returninnerFunc
One statement in the outer function is longer than it needs to be. Rewrite it. function outerFunc() {
  let greeting = "Hello";
  function innerFunc() {
    greeting = "G'day";
    console.log(greeting);
  }
  return innerFunc;
}
const aVar = outerFunc();
aVar();
let greeting; letgreeting;
Given the following code, what value will the console display? function count() {
  let num = 0;
  function incrementNum() {
    return num += 1;
  }
  return incrementNum;
}
const aVar = count();
console.log(aVar());
1 1
Given the following code, what value will the console display? function count() {
  let num = 0;
  function incrementNum() {
    return num += 1;
  }
  return incrementNum;
}
const aVar = count();
console.log(aVar() + aVar());
3 3
Given the following code, what value will be displayed? function outer() {
  let num = 0;
  function inner() {
    if (num < 1) {
      return 1;
    }
  }
  return inner;
}
const getNum = outer();
console.log(getNum());
1 1
  1. I've written a closure. Leave it intact.
  2. On the lines below it, code two statements.
  3. The first statement assigns a call to the outer function to a variable.
  4. In the second statement, an alert displays the returned value of the closure.
  5. Click the Result button (or, after revising, don't click, just wait).
  6. Wait a moment.
  7. If you've coded correctly, an alert will display "Hi"
  8. Dismiss the alert by clicking OK.
  9. For help with this code, see Chapter 60 in the book.
  1. My code is missing three lines. Code them so the alert displays "Hi".
  2. Click the Result button (or, after revising, don't click, just wait).
  3. Wait a moment.
  4. If you've coded correctly, an alert will display "Hi".
  5. Dismiss the alert by clicking OK.
  6. For help with this code, see Chapter 60 in the book.