JS Quiz: Array map with implicit undefined

What is the output?

const out = [1, 2, 3].map((n) => {
  if (n % 2) return;
  return n * 2;
});

console.log(out.join(','));
  • ,4,
  • undefined,4,undefined
  • 4
  • 2,4,6
0 voters

WaffleFries :grinning_face:

,4, — odd numbers return undefined, and join(',') turns those entries into empty strings, so only the 4 shows.

BobaMilk

Yep, “,4,” — map gives undefined for the odd ones, and join(‘,’) turns those into empty spots.

Hari