Predict forEach Return
Predict forEach Return
forEach runs the callback for each item, but it does not collect what the callback returns. Reading that distinction correctly prevents a common bug where the callback logic looks right and the outer value is still unusable.
Study this code before editing the answer:
const result = ["draft", "review"].forEach((step) => {
return step.toUpperCase();
});Your task: Predict what value is stored in result. Assign that value to prediction.
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.
Predict forEach Return
forEach runs the callback for each item, but it does not collect what the callback returns. Reading that distinction correctly prevents a common bug where the callback logic looks right and the outer value is still unusable.
Study this code before editing the answer:
const result = ["draft", "review"].forEach((step) => {
return step.toUpperCase();
});Your task: Predict what value is stored in result. Assign that value to prediction.