Back to questions
JuniorTheoryCommon
What does the program print?
const nums = [1, 2, 3, 4];
const result = nums.filter((n) => n % 2 === 0).map((n) => n * 10);
console.log(result.join(" "));20 40
- Expecting
10 30:filterkeeps the elements for which the function returnstrue, not the ones it drops, so the even numbers2and4stay. - Expecting
0 10 0 10:filterdoes not return the function's results likemap— it returns the original elements that passed, here[2, 4].
- What would the program print if
mapcame beforefilter? - Does
numschange after these two calls?