Higher Order Functions

forEach Side Effects

forEach Side Effects

forEach is often used when each callback call should update outside state. The callback return value is ignored, so returning true from inside the callback does not build a result for you.

That distinction matters in dashboards, import scripts, and cleanup jobs where you want to count, log, or trigger work for each matching item.

Your task: Complete countCompletedTasks so it returns how many tasks are marked complete. The function should work for any task list, including an empty one.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

forEach Side Effects

forEach is often used when each callback call should update outside state. The callback return value is ignored, so returning true from inside the callback does not build a result for you.

That distinction matters in dashboards, import scripts, and cleanup jobs where you want to count, log, or trigger work for each matching item.

Your task: Complete countCompletedTasks so it returns how many tasks are marked complete. The function should work for any task list, including an empty one.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Console

Run code to see output.