LearnFrenzy
Sign in Take a free test

Arrow Functions · Predict the Output · Question 17

this through nested arrows Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 17 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.js
const outer = {
  val: 7,
  run() {
    const a = () => {
      const b = () => this.val;
      return b();
    };
    return a();
  },
};
console.log(outer.run());
  • A undefined
  • B TypeError
  • C 7 Correct
  • D NaN
Correct Answer: Option C

Neither arrow has its own this, so both look outwards until they reach run(), whose this is outer.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links