Functions, this and closures: interview questions

bind, call and apply, currying, memoization, composing functions, and how this and closures behave. 38 questions from the Front End Interview Handbook. 10 have our own answer, built up from basic to advanced, with code that is proved by tests (how answers are checked).

  1. Implement Lodash functions: debounce(), throttle(), cloneDeep(), groupBy()Async, promises and timers, Functions, this and closures · basicJavaScript codingcheckednot tried
  2. Implement a function which extends Array.prototype.Arrays and objects, Functions, this and closures · reported at ByteDance/TikTokJavaScript codingcheckednot tried
  3. Implement a polyfill of Function.prototype.bind — handle the new keyword correctly.Functions, this and closures · reported at ByteDance/TikTokJavaScript codingcheckednot tried
  4. Implement a compose middleware function so that async middlewares like Koa-style f1, f2, f3 (each calling next()) execute in the correct nested order.Functions, this and closures, Async, promises and timers · reported at ByteDance/TikTokJavaScript codingcheckednot tried
  5. How do you make a function that takes a callback function fn and returns a function that calls fn on a timeout?Async, promises and timers, Functions, this and closures · reported at GoogleJavaScript codingcheckednot tried
  6. Implement throttle, for example allowing an input function to run at most once every 50 milliseconds.Async, promises and timers, Functions, this and closures · reported at GoogleJavaScript codingcheckednot tried
  7. Implement memoization, then extend the behavior as requirements change.Functions, this and closures · reported at LinkedInJavaScript codingcheckednot tried
  8. Implement a hand-rolled throttle; one screen prohibited library imports.Async, promises and timers, Functions, this and closures · reported at RipplingJavaScript codingcheckednot tried
  9. Implement Function.prototype.bind.Functions, this and closures · reported at RipplingJavaScript codingcheckednot tried
  10. Implement a rate limiter attribute/decoration/annotation on top of an API endpoint. Caps to N requests per minute with a rolling window. Source A and Source BFunctions, this and closures, Network and APIs · reported at UberJavaScript codingcheckednot tried
  11. Explain how this works in JavaScriptFunctions, this and closuresQuizhandbooknot tried
  12. Explain why the following doesn't work as an IIFE: function foo(){ }();. What needs to be changed to properly make it an IIFE?Functions, this and closuresQuizhandbooknot tried
  13. What is a closure, and how/why would you use one?Functions, this and closuresQuizhandbooknot tried
  14. What's the difference between .call and .apply?Functions, this and closuresQuizhandbooknot tried
  15. Explain Function.prototype.bind.Functions, this and closuresQuizhandbooknot tried
  16. Explain "hoisting".Functions, this and closuresQuizhandbooknot tried
  17. Make this work:Functions, this and closuresQuizhandbooknot tried
  18. Why is it, in general, a good idea to leave the global scope of a website as-is and never touch it?Functions, this and closuresQuizhandbooknot tried
  19. Why would you use something like the load event? Does this event have disadvantages? Do you know any alternatives, and why would you use those?Functions, this and closuresQuizhandbooknot tried
  20. What is the extent of your experience with Promises and/or their polyfills?Async, promises and timers, Functions, this and closuresQuizhandbooknot tried
  21. What is event loop? What is the difference between call stack and task queue?Async, promises and timers, Functions, this and closures · has a lessonQuizhandbooknot tried
  22. Can you offer a use case for the new arrow => function syntax? How does this new syntax differ from other functions?Functions, this and closuresQuizhandbooknot tried
  23. Can you give an example of a curry function and why this syntax offers an advantage?Functions, this and closuresQuizhandbooknot tried
  24. Why you would use a srcset attribute in an image tag? Explain the process the browser uses when evaluating the content of this attribute.HTML, Functions, this and closuresQuizhandbooknot tried
  25. What is a JavaScript closure?Functions, this and closures · reported at AmazonCodingno answer yetnot tried
  26. Implement Array.prototype functions like map, reduce, filter, sort.Arrays and objects, Functions, this and closures · reported at AmazonCodingno answer yetnot tried
  27. Given an object and a filter function, write a function that recursively filters the object, returning only values which return true when called with the filter function (like Array.prototype.filter but for objects).Arrays and objects, Functions, this and closures · reported at AmazonCodingno answer yetnot tried
  28. Walk through a past project, draw its workflow, and discuss improvements. An earlier candidate spent about 50 minutes on this conversation.Functions, this and closures, Frontend system design · reported at ByteDance/TikTokSystem designno answer yetnot tried
  29. Discuss how real-time comments reach and update a TikTok LIVE-style interface; one experience covered this conversationally rather than in a separate formal design round.Functions, this and closures, Frontend system design · reported at ByteDance/TikTokSystem designno answer yetnot tried
  30. "Tech execution" round: you're given a partially-implemented app and must fill in the missing pieces. The scope is comprehensive — basic utility functions, UI components, data fetching, JavaScript fundamentals. There's a test suite and your goal is to make each test pass.Functions, this and closures, UI components · reported at CoinbaseUser interface codingno answer yetnot tried
  31. Difference between callback and closure in JavaScript?Async, promises and timers, Functions, this and closures · reported at LinkedInQuizno answer yetnot tried
  32. What is a prototype?Functions, this and closures · reported at MicrosoftQuizno answer yetnot tried
  33. What is a closure?Functions, this and closures · reported at Microsoft, SalesforceQuizno answer yetnot tried
  34. Decomposition (Decomp) round: unlike typical FE system design, there's no whiteboarding and no deep technical dive. You explain and organize concepts in a plain text editor. Practice doing this without a diagramming tool. Highly interviewer-dependent — they're looking to see if you can think "like a Palantirian" and sync to their vocabulary.Functions, this and closures, CSS and layout · reported at PalantirSystem designno answer yetnot tried
  35. Design Pinterest (masonry feed) — Pinterest's own "masonry component" / dynamic image positioning is a popular reference for this round.Functions, this and closures, UI components · reported at PinterestSystem designno answer yetnot tried
  36. What is the difference between Array.prototype.map and Array.prototype.forEach?Arrays and objects, Functions, this and closures · reported at X/TwitterQuizno answer yetnot tried
  37. Open frontend system design — generally not tightly scoped to product domain.Functions, this and closures, Frontend system design · reported at UberSystem designno answer yetnot tried
  38. Build a React component; one applicant encountered this after preparing mainly for algorithms and JavaScript utilities.Functions, this and closures, React · reported at UberUser interface codingno answer yetnot tried