You can't break a forEach loop in JavaScript.#javascript #webdevelopment #programming #frontend — Transcript
Full transcript
- 0:004 years into JavaScript, I found a loop
- 0:03I could never stop. Did you know this?
- 0:06You write for each and when you hit
- 0:08three, you try to break.
- 0:09JavaScript throws a syntax error.
- 0:14So, you try return. It doesn't stop the
- 0:16loop. It only skips that one call and
- 0:18four and five still run.
- 0:22For years, I had no clue why. I just
- 0:24kept writing the loop and hoping.
- 0:28Then it clicked. It isn't a loop at all.
- 0:32The reason
- 0:34for each takes a callback and a callback
- 0:36is just a function. Return leaves that
- 0:38function, never the loop around it.
- 0:41Need to stop early? Use a for of loop
- 0:44where break works or some or every which
- 0:46stop as soon as the answer is known.
- 0:51MDN says the only way to stop for each
- 0:53is to throw an exception. If you need to
- 0:55stop, for each is the wrong tool.
- 0:58It took me 4 years to learn this. How
- 1:00long did it take you? Tell me in the
- 1:02comments and follow for more JavaScript.
About this transcript
This page contains the full transcript of You can't break a forEach loop in JavaScript.#javascript #webdevelopment #programming #frontend by Scale in 60 sec, generated from the public captions YouTube serves with the video. The transcript has 176 words across 24 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.