A programming language is said to have first class functions if functions are treated as any other variable and can be passed as arguments, returned from a function or can be assigned to a variable as value.
We need to filter an array of numbers to keep only the even ones. How would you write that using a function passed to Array.prototype.filter, and why does that work in JavaScript?
If you assign a function function add(a, b) { return a + b; } to a variable like const sum = add;, what can you do with sum that shows functions are first‑class?
Show a short example of using setTimeout with an inline function. What does passing a function to setTimeout illustrate about first‑class functions?
Our utility mapValues(obj, fn) started throwing because fn sometimes receives the wrong this context. Explain how treating functions as first‑class values can lead to this and how you’d fix it.
We refactored a module to accept a logging callback, but callers passing arrow functions see undefined errors. Walk me through why that happens with first‑class functions and lexical this.
Design a debounce helper that returns a new function wrapping the original. How does the fact that functions are first‑class enable this pattern, and what edge cases should you guard against?
Our event system lets plugins register handlers via register(eventName, handler). At scale we notice memory leaks because handlers aren’t released. Discuss how treating functions as first‑class objects affects garbage collection and what design changes you’d propose.
We want to let users supply custom validation logic that can be composed with built‑in validators. Sketch an API that leverages first‑class functions for composition while keeping performance acceptable.
A legacy codebase stores callbacks in a plain array and later invokes them with call. Occasionally a callback throws and crashes the process. Propose a more robust execution strategy using first‑class functions to isolate failures.
Our platform is moving from a callback‑heavy architecture to a declarative pipeline built on higher‑order functions. What architectural considerations—API surface, backward compatibility, team onboarding—arise when you promote functions to first‑class citizens at scale?
We plan to expose a shared plugin system where plugins are JavaScript functions executed in a sandbox across multiple microservices written in different languages. Explain the security, serialization, and versioning challenges of treating functions as first‑class assets across service boundaries.
When migrating a large codebase to treat functions as first‑class values for extensibility, how would you balance the need for runtime flexibility with compile‑time safety and long‑term maintainability?