JavaScript coding interview questions

87 questions from the Front End Interview Handbook’s javascript coding round. 61 have our own answer, built up from basic to advanced, with code that is proved by tests (how answers are checked).

  1. Implement Array.prototype functions: map, reduce, filter, sortArrays and objects · basicJavaScript codingcheckednot tried
  2. Implement Promise/Promise-related APIs: Promise, Promise.all, Promise.anyAsync, promises and timers · basic · has a lessonJavaScript codingcheckednot tried
  3. Implement Lodash functions: debounce(), throttle(), cloneDeep(), groupBy()Async, promises and timers, Functions, this and closures · basicJavaScript codingcheckednot tried
  4. Lodash's chunk()/map() with follow up of mapAsync(Promise.all) then mapWithChunksAsyncArrays and objects, Async, promises and timers · basicJavaScript codingcheckednot tried
  5. Convert all keys within an object into snake_case/camelCaseArrays and objects, Strings and parsing · basicJavaScript codingcheckednot tried
  6. DOM APIs: document.getElementByClassName(), document.getElementByTagName()The DOM · basicJavaScript codingcheckednot tried
  7. Observer patternPatterns: emitters, observers, stores · basicJavaScript codingcheckednot tried
  8. Write a templating engine that does variables substitution and simple conditionals.Strings and parsing · advancedJavaScript codingcheckednot tried
  9. Implement JSON.stringify().Strings and parsing, Arrays and objects · advancedJavaScript codingcheckednot tried
  10. Generate table of contents/outline from a HTML page (similar to Google Docs autogenerated outline).The DOM · advancedJavaScript codingcheckednot tried
  11. Given an API getAllLinks(url) that returns all the links on a page, write a function that returns all descendant links (child URLs of child URLs, etc.). Handle edge cases: circular dependencies, getAllLinks returning a promise, async efficiency, and time complexity.Async, promises and timers, Data structures and algorithms · reported at AdobeJavaScript codingcheckednot tried
  12. Implement a polyfill of Array.prototype.reduce.Arrays and objects · reported at AdobeJavaScript codingcheckednot tried
  13. Find the leaders in an array (every element greater than all elements to its right).Arrays and objects · reported at AdobeJavaScript codingcheckednot tried
  14. Implement a custom React hook that uses setInterval. Common gotcha: the interval double-fires unless you keep the callback in a useRef instead of useState.React, Async, promises and timers · reported at AdobeJavaScript codingcheckednot tried
  15. Write a simple promise.Async, promises and timers · reported at AirbnbJavaScript codingcheckednot tried
  16. Implement a Backbone-style StoreData class with key/value pairs and change listeners. One variation included a global change listener and required unset to remove data while retaining subscriptions. Setting the attribute again should notify those listeners. SourcePatterns: emitters, observers, stores · reported at AirbnbJavaScript codingcheckednot tried
  17. Implement Array.prototype methods (flat, map, reduce, concat) by yourself using JavaScript.Arrays and objects · reported at AppleJavaScript codingcheckednot tried
  18. How can you execute an array of promises in sequence?Async, promises and timers · reported at AppleJavaScript codingcheckednot tried
  19. Know Promise.any from memory.Async, promises and timers · reported at AtlassianJavaScript codingcheckednot tried
  20. Implement Promise.all.Async, promises and timers · reported at ByteDance/TikTok, LyftJavaScript codingcheckednot tried
  21. Implement a function which extends Array.prototype.Arrays and objects, Functions, this and closures · reported at ByteDance/TikTokJavaScript codingcheckednot tried
  22. Implement a polyfill of Function.prototype.bind — handle the new keyword correctly.Functions, this and closures · reported at ByteDance/TikTokJavaScript codingcheckednot tried
  23. Implement concurrency-limited async mapping. One earlier interview required a particular approach, so clarify scheduling constraints before coding.Async, promises and timers · reported at ByteDance/TikTokJavaScript codingcheckednot tried
  24. 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
  25. React-like VDOM but instead of creating DOM nodes, output an HTML string given an input object with type and attributes.React, The DOM · reported at ByteDance/TikTokJavaScript codingcheckednot tried
  26. Fix a buggy fetch helper: the provided function may look right but doesn't return the promise from fetch(...). You're expected to spot it.Async, promises and timers, Network and APIs · reported at DoorDashJavaScript codingcheckednot tried
  27. Implement getByClassName() and getByClassnameHierarchy()The DOM · reported at DropboxJavaScript codingcheckednot tried
  28. 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
  29. DFS on HTML nodes.The DOM, Data structures and algorithms · reported at GoogleJavaScript codingcheckednot tried
  30. 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
  31. Write a getElementsByClassName function.The DOM · reported at LinkedInJavaScript codingcheckednot tried
  32. Implement memoization, then extend the behavior as requirements change.Functions, this and closures · reported at LinkedInJavaScript codingcheckednot tried
  33. Implement an Event Emitter (Emitter Pattern).Patterns: emitters, observers, stores · reported at MetaJavaScript codingcheckednot tried
  34. Implement classnames — combine class names from strings, arrays, and conditional objects.Strings and parsing, Arrays and objects · reported at MetaJavaScript codingcheckednot tried
  35. Implement a Decryption class — focuses on managing async operations and a callback queue. The provided decryptEncrypt(key, payload, callback) generates a new key per call; your class must enqueue callbacks and process them in order as decryption completes. (The name is misleading — it's an async-operations question, not a security question.)Async, promises and timers · reported at MetaJavaScript codingcheckednot tried
  36. Find the identical DOM node in two identical trees: given a node in one tree, locate the equivalent node in the other tree by reference. Efficient solution: walk up via parentNode, record the path, then replay the path in the other tree (avoids touching unrelated nodes vs. DFS/BFS).The DOM · reported at MetaJavaScript codingcheckednot tried
  37. Implement a number/character pad like old flip phones — buttons where 2 = abc, 3 = def, etc. Pressing the same key cycles through letters within a short time window; after a delay, the next press appends. e.g. press 2 → a, press 2 again → b, wait 1s and press 2 → ba, press 6 → bam.Async, promises and timers, Strings and parsing · reported at MicrosoftJavaScript codingcheckednot tried
  38. Rabin-Karp string-matching DSA problem (recurring at Microsoft).Strings and parsing, Data structures and algorithms · reported at MicrosoftJavaScript codingcheckednot tried
  39. Implement Squash Object — flatten a nested object into a single-level object with dot-separated keys.Arrays and objects · reported at OracleJavaScript codingcheckednot tried
  40. Evaluate a basic arithmetic expression string like "1+3-2" and print the output. Handle all edge cases (no BODMAS required).Strings and parsing · reported at OracleJavaScript codingcheckednot tried
  41. Find common elements between two arrays — e.g. arr1 = [1, 2, 2, 4, 5], arr2 = [3, 2, 4, 2] → [2, 2, 4]. Follow-up: extend to matrices instead of two arrays.Arrays and objects · reported at OracleJavaScript codingcheckednot tried
  42. Intervals problem: design a class with related methods (insert, overlap, merge) over a list of intervals.Data structures and algorithms · reported at PalantirJavaScript codingcheckednot tried
  43. Given a text and a query of two words plus an integer k, return the indices in the text where the distance between the two words is ≤ k.Strings and parsing, Data structures and algorithms · reported at PalantirJavaScript codingcheckednot tried
  44. "Can you win" — variant of LeetCode Jump Game I/II. Medium-level DSA, you should be able to solve 2 in 20-30 minutes.Data structures and algorithms · reported at PinterestJavaScript codingcheckednot tried
  45. Given an array of integers like [1,2,0,4,3] and a starting index, return true if you can reach a 0 value. Each value is how many steps left/right you can move (you must take exactly that many). Wrap around from end to start when you run out of room. Solve recursively with visited-index tracking, then convert to an iterative queue-based solution as a follow-up.Data structures and algorithms · reported at PinterestJavaScript codingcheckednot tried
  46. Given a stream of comments, detect inappropriate language. Requires a trie data structure.Data structures and algorithms, Strings and parsing · reported at PinterestJavaScript codingcheckednot tried
  47. Deduplicate a list of messages without using an object or a Set.Arrays and objects · reported at RedditJavaScript codingcheckednot tried
  48. Read HTML form data and construct a JSON object.The DOM, HTML · reported at RedditJavaScript codingcheckednot tried
  49. Implement Event Emitter.Patterns: emitters, observers, stores · reported at RipplingJavaScript codingcheckednot tried
  50. Implement a hand-rolled throttle; one screen prohibited library imports.Async, promises and timers, Functions, this and closures · reported at RipplingJavaScript codingcheckednot tried
  51. Dedupe a list of fetched items by ID using a Set of seen IDs.Arrays and objects · reported at RipplingJavaScript codingcheckednot tried
  52. Implement flatten on a nested array.Arrays and objects · reported at RipplingJavaScript codingcheckednot tried
  53. Implement Function.prototype.bind.Functions, this and closures · reported at RipplingJavaScript codingcheckednot tried
  54. Implement an event emitter progressively in 3 stages of increasing complexity. Senior / staff candidates are expected to clear all 3 stages.Patterns: emitters, observers, stores · reported at RobinhoodJavaScript codingcheckednot tried
  55. Flatten a nested array.Arrays and objects · reported at SalesforceJavaScript codingcheckednot tried
  56. LeetCode-style: "high five problem" variant (sort + average scores per student).Arrays and objects, Data structures and algorithms · reported at SalesforceJavaScript codingcheckednot tried
  57. LeetCode-style: calculate the distance a robot has moved given a sequence of instructions.Data structures and algorithms · reported at SalesforceJavaScript codingcheckednot tried
  58. 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
  59. Implement an async process queue with concurrency control. Follow-up: handle async-task failures by accepting an error callback handler.Async, promises and timers · reported at UberJavaScript codingcheckednot tried
  60. Build a utility in JS that sends data in batches with a timeout: as soon as the batch size is reached, send immediately and restart the timer; if the timer fires before the batch is filled, send what's there and restart.Async, promises and timers · reported at UberJavaScript codingcheckednot tried