Question 3
Back to Exercise
What does [].reduce((sum, x) => sum + x) do?
- A Returns 0
- B Throws a TypeError: Reduce of empty array with no initial value Correct
- C Returns undefined
- D Returns an empty array
Correct Answer: Option B
With no elements and no initial value there is nothing to start from. Passing an initial value (0) makes it return 0.
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!