reactjs / reactjs/react.dev

Change Missing From Changelog: forEach() Loop's `Return` returns to forEach()'s invocation point, not to the calling function.

Open
#2,732 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
11.8k
Forks
7.9k
Avg merge
1d 11h
Merged PRs (30d)
11

Description

Hey all,

I'm noticing that in upgrading to ReactJS Version 16.12.0 from 16.7.0, the behavior of foreach was changed, so that return returns to where foreach is called, and not the function calling the function containing the foreach. But I don't see this change here:

https://github.com/facebook/react/blob/master/CHANGELOG.md

Basically,

function1() {
	function2();
	console.log("function 1");
}

function2() {
	const arr = ['cool'];
	arr.forEach((var) => {
		return var;
	});
	console.log("function 2");
}

Before 16.12.0, console output was: "function 1", but now it is "function 2; function 1." This change appears to be against MDN documentation and internet consensus: https://stackoverflow.com/questions/34653612/what-does-return-keyword-mean-inside-foreach-function

But it should have been included in the changelog, though I am not seeing it. Let me know if I'm misunderstanding.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with CHANGELOG.md and the React 16.12.0 changelog entry referenced in the issue. Verify the reported forEach() behavior against the linked MDN and Stack Overflow references, then determine whether the changelog is missing an entry; done means the report is validated and the changelog accurately reflects the release if appropriate.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.