The Difference Between Map and ForEach

Owen Abbott
1 min readOct 4, 2020

--

I was asked during the mock technical interview to explain the difference between .map and .forEach.

I figure that if a technical recruiter finds this to be an adequate display of technical skills, it is an adequate subject to write on.

So here it is: the difference between Map and forEach is that Map mutates the original array in the way that you specify, while forEach creates a copy of the original array that’s changed in the way you specify. Map is destructive while forEach is not.

I was graded a 4 out of 5 on that interview, based on my answers to these questions and my solution to a code problem (I didn’t know the answer to one of the questions because I was unfamiliar with the terminology.)

So there you have it.

Now you know.

--

--

No responses yet