Question 11
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const f = (a, b = a * 2, ...rest) => [a, b, rest.length];
console.log(f(1), f(1, 5, 7, 8));
- A [ 1, 2, 0 ] [ 1, 5, 3 ]
- B [ 1, undefined, 0 ] [ 1, 5, 2 ]
- C SyntaxError
- D [ 1, 2, 0 ] [ 1, 5, 2 ] Correct
Correct Answer: Option D
Arrows support defaults (which may use earlier parameters) and rest parameters exactly like regular functions.
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!