Question 18
Back to Exercise
What does the following JavaScript code print (console output, as in Node.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!