LearnFrenzy
Sign in Take a free test

Loops · JavaScript Loops MCQ · Question 13

forEach and holes Answer, explanation & discussion

  • MCQ
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 13 Back to Exercise

How many times does [1, , 3].forEach(fn) call fn?

  • A 3 – the hole is passed as undefined
  • B 2 – forEach skips the hole Correct
  • C 1
  • D 0 – sparse arrays cannot be iterated
Correct Answer: Option B

forEach, map, filter, reduce and for…in skip holes. A classic for loop and for…of visit index 1 and read undefined.

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