Practice & Assessment
Test your understanding of Functions and Scope
Multiple Choice Questions
5What does this code output? const fn = function hello() { return hello.name; }; console.log(fn.name);
Which output does this produce? for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 0); }
What is the output of the following? function outer() { let x = 10; return () => x * 2; } const fn = outer(); console.log(fn());
What does Array.prototype.reduce return when called with no initial accumulator on a single-element array?
What is the difference between rest parameters and the arguments object?
Coding Challenges
1Function Pipeline Builder
Write a function compose(...fns) that takes any number of single-argument functions and returns a new function that applies them right to left. Input: compose(double, addOne, square)(3) should square 3 (9), add one (10), then double (20). Output: the final computed value. All input functions take and return numbers. Time estimate: 20 minutes.
Mini Project
Functional Data Dashboard
Given a hardcoded array of 20 student objects each with { name, grade, subject, score }, build a Node.js script that uses map, filter, and reduce to: (1) filter students with score above 70, (2) map them to { name, grade, percentile } where percentile is score/100, (3) group them by subject using reduce into an object keyed by subject name, (4) log a formatted summary showing each subject, count of passing students, and average percentile. Use at least one closure (e.g., a configurable threshold function), arrow functions throughout, rest/spread somewhere logical, and default parameters in at least one helper function.
