Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1nums.forEach(show); | AWrites an arrow function directly in the call as a callback that map runs on every item | |
| 2nums.map(n => n * 2); | BPasses the function show as a callback, with no brackets, so forEach calls it once for each item | |
| 3To pass a function as a callback, write its name without brackets | CThe brackets after show call the function straight away, so its result (undefined) is passed instead of the function. Write forEach(show). | |
| 4forEach, map and filter each need a callback so they know what to do with every item | DThis passes the value n * 2, not a function. The callback needs an arrow function: map(n => n * 2). | |
| 5nums.forEach(show()); | Escores.filter(isPass); | |
| 6nums.map(n * 2); | Fnames.forEach(name => console.log(name)); |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
callback — A function passed as an argument, without brackets, to another function that calls it later. Examples: nums.forEach(show) or nums.map(n => n * 2).function show(n) { console.log(n); }
nums.forEach(show);const doubled = nums.map(n => n * 2);const big = nums.filter(n => n > 10);nums.forEach(n => console.log(n));function repeat(action) {
action();
}
repeat(() => console.log("Hi"));