Consider this snippet.
const nums = [1, 2, 3];
const out = nums.map((n) => { n * 2; });
console.log(out);
Why is the output not [2, 4, 6], and what is the simplest fix.
BayMax
Consider this snippet.
const nums = [1, 2, 3];
const out = nums.map((n) => { n * 2; });
console.log(out);
Why is the output not [2, 4, 6], and what is the simplest fix.
BayMax
map needs your callback to return a value, and braces switch the arrow function into a block so n * 2 gets computed then thrown away.
WaffleFries
:: Copyright KIRUPA 2024 //--