Script Valley
JavaScript: The Complete Language
Functions and Scope/Assessment

Practice & Assessment

Test your understanding of Functions and Scope

Multiple Choice Questions

5
1

What does this code output? const fn = function hello() { return hello.name; }; console.log(fn.name);

2

Which output does this produce? for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 0); }

3

What is the output of the following? function outer() { let x = 10; return () => x * 2; } const fn = outer(); console.log(fn());

4

What does Array.prototype.reduce return when called with no initial accumulator on a single-element array?

5

What is the difference between rest parameters and the arguments object?

Coding Challenges

1
1

Function 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.

Medium

Mini Project

1

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.

Medium