Time: 0:00
Test a custom input to verify an edge case (e.g. empty lists, negative numbers, duplicates).
This bug belongs to the logic errors pattern
The wrong operator, an inverted condition, a formula the right way round but backwards.
What went wrong: Array.prototype.find() returns 0 when target is 0. Checking !found treats 0 as falsy and incorrectly enters the error branch.
The fix: Explicitly check for undefined: if (found === undefined)
Remember: In JavaScript, array.find() returns undefined when not found; check for undefined instead of using truthy negation.
The pattern behind it: logic errors.
Paste this into any web page or blog post. Visitors fix the bug right there, in their browser.
<iframe src="https://trybughunt.com/embed/e56db95e-462d-4dfb-acbf-f2c4f60d76b4" title="Debugging challenge: Array find returning zero treated as not found" width="100%" height="580" loading="lazy" style="border:1px solid #d4d4d8;border-radius:12px;max-width:760px"></iframe>
<p style="font-size:14px">Debugging challenge from <a href="https://trybughunt.com/challenges/e56db95e-462d-4dfb-acbf-f2c4f60d76b4">TryBugHunt</a></p>