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!