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

Care to give a hint? :grinning_face_with_smiling_eyes: Don’t actually provide the answer though.

Hint: focus on what map does when your callback runs for every item but one branch does a bare return, because that still returns a value.

WaffleFries