What interviewers listen for
They want a correct mental model, not a memorized snippet. Narrate how you walk the array, handle holes, and preserve the original collection.
- API contract clarity
- Edge-case coverage
- Readable, testable code
JavaScript polyfills
Polyfill interview questions test whether you can rebuild the APIs you use every day. Practice them in a live editor until callbacks, iteration, and edge cases are second nature.
A strong polyfill answer starts with the public contract: inputs, return value, mutation rules, and how thisArg or initialValue change behavior.
After polyfills, practice promise helpers and function utilities — then use those patterns inside UI rounds where you need reliable async and event handling.
They want a correct mental model, not a memorized snippet. Narrate how you walk the array, handle holes, and preserve the original collection.
Start with array methods and call/apply-style binding helpers, then move to promise combinators to practice ordering, rejection and asynchronous completion.
Implement once from memory, write a few assertion cases, then re-implement under a timer. Compare with your previous solution for clarity.
For an array-only implementation, validate the callback, capture the starting length and create a result array of that length. Visit each index that exists, call the callback with thisArg and the value, index and input array, then store its result at the same index. Return the result without writing to the input. This exercise does not implement the full native specification.
Ask whether an initial value is supplied before choosing the first accumulator. Without one, start from the first present element; an empty array with no initial value must throw. Skip holes rather than treating them as undefined values.
Implement Promise.all and Promise.any separately: their rejection rules differ. Use the linked exercises to test each contract before comparing solutions.
Polyfill questions ask you to reimplement standard APIs (like Array.map, reduce, or Function.call) to prove you understand the language mechanics behind everyday methods.
They reveal whether you understand callbacks, `this`, iteration, edge cases, and API contracts — skills that transfer to debugging production JS and writing reliable utilities.
Cover the documented happy path and the edge cases interviewers usually probe (empty arrays, sparse arrays, thisArg, missing initial values). Full spec compliance is rarely required.
Pair polyfills with promise utilities, debounce/throttle, flatten, and deep clone — then apply those skills inside React machine coding rounds.