LearnFrenzy
Sign in Take a free test

Arrow Functions · Predict the Output · Question 18

length and name of arrow functions Answer, explanation & discussion

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

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

main.js
const sum = (a, b, ...c) => 0;
console.log(sum.length, sum.name, JSON.stringify((() => {}).name));
  • A 3 sum ""
  • B 2 sum "" Correct
  • C 2 anonymous "anonymous"
  • D 2 sum "arrow"
Correct Answer: Option B

length counts parameters before the rest parameter. An arrow assigned to a variable takes its name; an arrow that is never assigned has an empty name.

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