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).
- Implement Lodash functions:
debounce(),throttle(),cloneDeep(),groupBy()Async, promises and timers, Functions, this and closures · basicJavaScript codingcheckednot tried - Implement a function which extends
Array.prototype.Arrays and objects, Functions, this and closures · reported at ByteDance/TikTokJavaScript codingcheckednot tried - Implement a polyfill of
Function.prototype.bind— handle thenewkeyword correctly.Functions, this and closures · reported at ByteDance/TikTokJavaScript codingcheckednot tried - Implement a
composemiddleware function so that async middlewares like Koa-stylef1,f2,f3(each callingnext()) execute in the correct nested order.Functions, this and closures, Async, promises and timers · reported at ByteDance/TikTokJavaScript codingcheckednot tried - How do you make a function that takes a callback function
fnand returns a function that callsfnon a timeout?Async, promises and timers, Functions, this and closures · reported at GoogleJavaScript codingcheckednot tried - 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 - Implement memoization, then extend the behavior as requirements change.Functions, this and closures · reported at LinkedInJavaScript codingcheckednot tried
- Implement a hand-rolled
throttle; one screen prohibited library imports.Async, promises and timers, Functions, this and closures · reported at RipplingJavaScript codingcheckednot tried - Implement
Function.prototype.bind.Functions, this and closures · reported at RipplingJavaScript codingcheckednot tried - 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
- Explain how
thisworks in JavaScriptFunctions, this and closuresQuizhandbooknot tried - 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 - What is a closure, and how/why would you use one?Functions, this and closuresQuizhandbooknot tried
- What's the difference between
.calland.apply?Functions, this and closuresQuizhandbooknot tried - Explain
Function.prototype.bind.Functions, this and closuresQuizhandbooknot tried - Explain "hoisting".Functions, this and closuresQuizhandbooknot tried
- Make this work:Functions, this and closuresQuizhandbooknot tried
- 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
- Why would you use something like the
loadevent? Does this event have disadvantages? Do you know any alternatives, and why would you use those?Functions, this and closuresQuizhandbooknot tried - What is the extent of your experience with Promises and/or their polyfills?Async, promises and timers, Functions, this and closuresQuizhandbooknot tried
- 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
- 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
- Can you give an example of a curry function and why this syntax offers an advantage?Functions, this and closuresQuizhandbooknot tried
- Why you would use a
srcsetattribute in an image tag? Explain the process the browser uses when evaluating the content of this attribute.HTML, Functions, this and closuresQuizhandbooknot tried - What is a JavaScript closure?Functions, this and closures · reported at AmazonCodingno answer yetnot tried
- Implement
Array.prototypefunctions likemap,reduce,filter,sort.Arrays and objects, Functions, this and closures · reported at AmazonCodingno answer yetnot tried - Given an object and a filter function, write a function that recursively filters the object, returning only values which return
truewhen called with the filter function (likeArray.prototype.filterbut for objects).Arrays and objects, Functions, this and closures · reported at AmazonCodingno answer yetnot tried - 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
- 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
- "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
- Difference between callback and closure in JavaScript?Async, promises and timers, Functions, this and closures · reported at LinkedInQuizno answer yetnot tried
- What is a prototype?Functions, this and closures · reported at MicrosoftQuizno answer yetnot tried
- What is a closure?Functions, this and closures · reported at Microsoft, SalesforceQuizno answer yetnot tried
- 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
- 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
- What is the difference between
Array.prototype.mapandArray.prototype.forEach?Arrays and objects, Functions, this and closures · reported at X/TwitterQuizno answer yetnot tried - 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
- 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