TypeScript · Junior · Question 64 of 75
Why can [1, 2].forEach((n) => console.log(n)) pass a callback with one parameter when forEach passes three?
- ✓Correct answer: A function with fewer parameters is assignable to a function type with more - extra arguments are simply ignored
- 2TypeScript adds the missing parameters
- 3
forEachonly passes one argument
Explanation
This mirrors common JavaScript practice. The opposite (a callback requiring more parameters than provided) is an error.