LearnFrenzy
Sign in Take a free test

Loops · JavaScript Loops MCQ · Question 4

break inside forEach Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

What happens if you write break directly inside a forEach callback?

  • A SyntaxError: break is only allowed inside a loop or switch, and the callback is a separate function Correct
  • B The forEach stops
  • C Only the current element is skipped
  • D It is ignored
Correct Answer: Option A

The callback is a function, not a loop body, so break is illegal there ("Illegal break statement"). Use for…of with break, or some/find.

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