but forMap can change the array value with its callback but in case of forEach, can't. so can anyone tell me two different behavior of callback?
You basically nailed it, so what exactly you want to figure out?
forEach and map both take callback as a parameter, but in case of map, we can change the array value by doing operation over it, but in case of forEach we can't do operations on array element. so how it is possible, we are passing same callback to both of them, but one callback do its work but other one donot
That behavior by design, you give same callback, but it applies differently in map and forEach. If you have any doubt, try search for self-made implementations of forEach and map, it should be clear enough
Обсуждают сегодня