Sobes.tech
Middle

There is an array of 10 elements, and .map() is called. What will happen if you remove the return statement from the callback?

sobes.tech AI

Answer from AI

If you remove the return statement in the callback passed to the .map() method, the function will return undefined by default. As a result, the new array created by .map() will consist of undefined for each element.

Example:

const arr = [1, 2, 3];
const result = arr.map(x => { x * 2; });
console.log(result); // [undefined, undefined, undefined]

For .map() to work correctly, you need to explicitly return a value from the callback:

const result = arr.map(x => x * 2);
console.log(result); // [2, 4, 6]