map() returns a new array with the results of the operation performed on each element, while forEach() simply performs the operation on each element without returning anything. Additionally, map() does not modify the original array while forEach() can modify the original array.
map() method can also modify the original array.
However, it's important to note that modifying the original array with map() is not a recommended practice as it can lead to unexpected behavior and make the code harder to understand and maintain. It's better to use map() to create a new array with the desired changes and leave the original array unchanged.
So our answer should be , map() returns a new array with the results of the operation performed on each element, while forEach() simply performs the operation on each element without returning anything.
Don’t say map() does not modify the original array while forEach() can modify the original array.
#frontend #frontenddeveloper #interview #javascript
On this page of the site you can watch the video online Map vs ForEach | Most asked Javascript Interview Question | with a duration of hours minute second in good quality, which was uploaded by the user CodingLesson 04 March 2023, share the link with friends and acquaintances, this video has already been watched 323 times on youtube and it was liked by 12 viewers. Enjoy your viewing!