r/HackerEarthCommunity • u/Neil_at_HackerEarth • 4d ago
JavaScript developers, what will this print? Don't run it.
A small JavaScript question for today.
const numbers = [1, 2, 3, 4, 5];
const result = numbers.map((num) => {
if (num > 3) {
return;
}
return num * 2;
});
console.log(result);
What do you think the output will be?
Option A: [2, 4, 6, 8, 10]
Option B: [2, 4, undefined, undefined, undefined]
Option C: [2, 4]
Option D: Something else?
Don't just drop the option. Explain why you think that's the output.
5
Upvotes
2
u/FlamboyantApproval16 4d ago
D: [2, 4, 6, undefined, undefined]