LearnFrenzy
Sign in Take a free test

Array Methods · Array Methods MCQ · Question 3

reduce on an empty array Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links