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
What is the output?
const out = [1, 2, 3].map((n) => {
if (n % 2) return;
return n * 2;
});
console.log(out.join(','));
WaffleFries
Care to give a hint?
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
:: Copyright KIRUPA 2024 //--