Can You Stop for Each in JavaScript?
<p><strong>Can you stop a forEach loop in JavaScript?</strong> This is a question I was once asked during an interview, and my initial response was, <strong>“No, I can’t do that.”</strong></p>
<p><strong>Unfortunately, my response led the interviewer to end the interview abruptly.</strong></p>
<p>Frustrated with the outcome, I asked the interviewer, “Why? Is it actually possible to stop a forEach loop in JavaScript?”</p>
<p>Before the interviewer could answer, I took a moment to explain my understanding of why we couldn’t directly stop a forEach loop in JavaScript.</p>
<h1>Is my answer correct?</h1>
<p>My friends, what numbers will be output by the following code?</p>
<p>Will it output just one number or more?</p>
<p>Yes, it will output ‘0’, ‘1’, ‘2’, ‘3’.</p>
<p><a href="https://javascript.plainenglish.io/interview-can-you-stop-foreach-in-javascript-724d9d76fd72">Website</a></p>