Skip to content
Quiz · Functions · lesson 8 of 10

Quiz — a callback with one parameter

What happens when this program is compiled and run (lines separated by spaces)?

TypeScript
type Handler = (value: number, index: number) => void;
function each(nums: number[], fn: Handler) {
    for (let i = 0; i < nums.length; i++) {
        fn(nums[i], i);
    }
}
each([1, 2], (v) => console.log(v));