find vs filter, and some vs every?
Quick answer
find returns the first match (or undefined); filter returns all matches. some checks if any pass; every checks if all pass.
In detail
Use `find` when you want one item, `filter` when you want every match (always returns an array). `some` returns true if at least one element passes the test; `every` returns true only if all do (and true for an empty array).
[1,2,3].find(n => n > 1); // 2
[1,2,3].filter(n => n > 1); // [2, 3]
[1,2,3].some(n => n > 2); // true
[1,2,3].every(n => n > 0); // trueWhy interviewers ask this: Confirms you pick the right method for the job.
This is 1 of 118+ questions in the JavaScript Interview Kit
Get every question with detailed answers, follow-ups and real code — plus coding challenges and a last-minute revision sheet. One-time payment, instant access.
⚡ Get the JavaScript Interview Kit → ₹299