Practice
Frontend coding questions, solved line by line.
Write the code interviews ask for, run it against tests in your browser, then read a walkthrough of every line, with links to the lessons behind each idea.
- questions
- 229
- topics
- 26
- companies tagged
- 42
How it works
- Open any question and read it. Free.
- Sign in, free, to run your code against the tests.
- The line-by-line explanation and the lessons come with the course.
229 questions
01Types, equality and numbers8 questions
- 1.1Swap two numbers without a temporary variableWhich companies ask this question comes with the courseEasy5–15 min
- 1.2Precise type checksWhich companies ask this question comes with the courseEasy10–20 min
- 1.3Is the value empty?Which companies ask this question comes with the courseEasy10–15 min
- 1.4Size of any collectionWhich companies ask this question comes with the courseEasy10–15 min
- 1.5Detect NaN and integersWhich companies ask this question comes with the courseEasy10–15 min
- 1.6Clamp, in-range and meanWhich companies ask this question comes with the courseEasy10–20 min
- 1.7Random integer in a range, and a random hex colorWhich companies ask this question comes with the courseEasy10–20 min
- 1.8Days between two dates, and 12-hour to 24-hour timeWhich companies ask this question comes with the courseMedium15–25 min
02Strings and text10 questions
- 2.1Reverse a string, its words, and each wordWhich companies ask this question comes with the courseEasy10–15 min
- 2.2String.prototype.repeatWhich companies ask this question comes with the courseEasy10–20 min
- 2.3String.prototype.splitWhich companies ask this question comes with the courseMedium15–30 min
- 2.4Truncate to a number of characters or wordsWhich companies ask this question comes with the courseEasy10–20 min
- 2.5Replace every space with an underscore, three waysWhich companies ask this question comes with the courseEasy5–15 min
- 2.6Count the characters between the first and last "X"Which companies ask this question comes with the courseEasy5–15 min
- 2.7Format a list as "a, b and c"Which companies ask this question comes with the courseMedium15–25 min
- 2.8Validate an email and a strong password with regular expressionsWhich companies ask this question comes with the courseMedium20–30 min
- 2.9Convert between camelCase, snake_case and kebab-caseWhich companies ask this question comes with the courseEasy15–25 min
- 2.10Count words and find the most frequent characterWhich companies ask this question comes with the courseEasy10–20 min
03Array methods from scratch9 questions
- 3.1Array.prototype.mapWhich companies ask this question comes with the courseEasy10–20 min
- 3.2Array.prototype.filterWhich companies ask this question comes with the courseEasy10–20 min
- 3.3Array.prototype.reduceWhich companies ask this question comes with the courseMedium15–30 min
- 3.4Array.prototype.at and Array.prototype.withWhich companies ask this question comes with the courseEasy10–20 min
- 3.5Array.prototype.concatWhich companies ask this question comes with the courseEasy10–20 min
- 3.6indexOf and includesWhich companies ask this question comes with the courseMedium15–30 min
- 3.7Array.prototype.flat to any depthWhich companies ask this question comes with the courseMedium15–30 min
- 3.8Array.prototype.square and average on every arrayWhich companies ask this question comes with the courseEasy10–20 min
- 3.9Array helpers on the prototype without breaking for…inWhich companies ask this question comes with the courseMedium15–30 min
04Array utilities14 questions
- 4.1Split an array into chunksWhich companies ask this question comes with the courseEasy10–15 min
- 4.2Remove falsy valuesWhich companies ask this question comes with the courseEasy5–10 min
- 4.3Fill, range and range from the rightWhich companies ask this question comes with the courseEasy15–20 min
- 4.4Drop items while a test holds (from either end)Which companies ask this question comes with the courseEasy10–15 min
- 4.5Find the first and last index matching a testWhich companies ask this question comes with the courseEasy10–20 min
- 4.6Max, min and mean by a keyWhich companies ask this question comes with the courseEasy10–20 min
- 4.7Remove duplicates (values and by key)Which companies ask this question comes with the courseEasy10–20 min
- 4.8Difference, intersection and union (plain, by key, with a comparator)Which companies ask this question comes with the courseMedium20–35 min
- 4.9Count and group by a keyWhich companies ask this question comes with the courseEasy10–20 min
- 4.10Object from key-value pairs, and backWhich companies ask this question comes with the courseEasy10–20 min
- 4.11Shuffle an array fairlyWhich companies ask this question comes with the courseMedium15–25 min
- 4.12Sort objects by several keys (last name, then first)Which companies ask this question comes with the courseMedium20–30 min
- 4.13Replace the middle three items of one array with another'sWhich companies ask this question comes with the courseEasy10–15 min
- 4.14Index topics by tag and look them upWhich companies ask this question comes with the courseMedium20–35 min
05Objects and property control8 questions
- 5.1Map an object's valuesWhich companies ask this question comes with the courseEasy10–20 min
- 5.2Check an object against a set of rulesWhich companies ask this question comes with the courseEasy10–20 min
- 5.3Empty an object in placeWhich companies ask this question comes with the courseEasy10–20 min
- 5.4A property that cannot go below zeroWhich companies ask this question comes with the courseEasy10–20 min
- 5.5A property that can be set only onceWhich companies ask this question comes with the courseMedium15–30 min
- 5.6Chain method calls (obj.a().b().c())Which companies ask this question comes with the courseEasy10–20 min
- 5.7Freeze an object deeplyWhich companies ask this question comes with the courseMedium15–30 min
- 5.8Object entries into a Map and backWhich companies ask this question comes with the courseEasy10–20 min
06Functions and closures9 questions
- 6.1A counter with private stateWhich companies ask this question comes with the courseEasy5–10 min
- 6.2A counter with increment, decrement and resetWhich companies ask this question comes with the courseEasy10–15 min
- 6.3Run a function only onceWhich companies ask this question comes with the courseEasy10–15 min
- 6.4Cycle through values on each callWhich companies ask this question comes with the courseEasy5–10 min
- 6.5Allow a function at most n callsWhich companies ask this question comes with the courseEasy10–15 min
- 6.6A calculator object shared across callsWhich companies ask this question comes with the courseEasy15–20 min
- 6.7Toggle through a list of valuesWhich companies ask this question comes with the courseEasy15–20 min
- 6.8Log every call's time without changing the functionWhich companies ask this question comes with the courseMedium20–30 min
- 6.9Negate a predicate; compose and pipe functionsWhich companies ask this question comes with the courseEasy15–20 min
07this, call, apply and bind6 questions
- 7.1Count a function's declared parameters and the arguments it receivedWhich companies ask this question comes with the courseEasy10–15 min
- 7.2Implement Function.prototype.callWhich companies ask this question comes with the courseMedium20–30 min
- 7.3Implement Function.prototype.applyWhich companies ask this question comes with the courseMedium20–30 min
- 7.4Implement Function.prototype.bind (with new)Which companies ask this question comes with the courseHard30–45 min
- 7.5A bind that an explicit this can still overrideWhich companies ask this question comes with the courseHard30–45 min
- 7.6Predict this in eight callsWhich companies ask this question comes with the courseMedium15–25 min
08Currying and memoization8 questions
- 8.1multiply(a)(b)Which companies ask this question comes with the courseEasy5–10 min
- 8.2Curry a function of fixed lengthWhich companies ask this question comes with the courseMedium15–25 min
- 8.3Curry with placeholdersWhich companies ask this question comes with the courseHard30–45 min
- 8.4sum(a)(b)(c) with any groupingWhich companies ask this question comes with the courseMedium15–25 min
- 8.5Keep adding until an empty callWhich companies ask this question comes with the courseMedium15–25 min
- 8.6Memoize a functionWhich companies ask this question comes with the courseEasy10–15 min
- 8.7Memoize with a key resolver and a size limitWhich companies ask this question comes with the courseMedium20–30 min
- 8.8Memoize methods per objectWhich companies ask this question comes with the courseHard30–45 min
09Prototypes and classes6 questions
- 9.1An Employee class with a private salaryWhich companies ask this question comes with the courseEasy10–20 min
- 9.2A singletonWhich companies ask this question comes with the courseEasy10–20 min
- 9.3Methods only real instances can callWhich companies ask this question comes with the courseMedium20–30 min
- 9.4Inheritance without classWhich companies ask this question comes with the courseMedium20–30 min
- 9.5An observable model with change eventsWhich companies ask this question comes with the courseMedium25–35 min
- 9.6Implement instanceofWhich companies ask this question comes with the courseMedium15–25 min
10Proxies, iterators and generators6 questions
- 10.1next() over an array, one value per callWhich companies ask this question comes with the courseEasy10–20 min
- 10.2An object that behaves like an array (push, pop, length)Which companies ask this question comes with the courseMedium15–30 min
- 10.3An array that accepts only stringsWhich companies ask this question comes with the courseMedium15–30 min
- 10.4Array items reachable by index and by idWhich companies ask this question comes with the courseMedium15–30 min
- 10.5Negative indexes with a ProxyWhich companies ask this question comes with the courseMedium15–30 min
- 10.6Generators: random numbers, a range and a search through nested dataWhich companies ask this question comes with the courseMedium20–35 min
11Timers8 questions
- 11.1Print 1 to 10, one per secondWhich companies ask this question comes with the courseEasy10–20 min
- 11.2Write setTimeout with requestAnimationFrameWhich companies ask this question comes with the courseMedium15–30 min
- 11.3A cancellable timeout and intervalWhich companies ask this question comes with the courseEasy10–20 min
- 11.4An interval you can pause and resumeWhich companies ask this question comes with the courseMedium20–30 min
- 11.5Clear every pending timerWhich companies ask this question comes with the courseMedium20–30 min
- 11.6SleepWhich companies ask this question comes with the courseEasy10–20 min
- 11.7Chain calls with optional delaysWhich companies ask this question comes with the courseMedium20–35 min
- 11.8A countdown that stays right in a background tabWhich companies ask this question comes with the courseMedium20–30 min
12Callbacks, promises and async12 questions
- 12.1Run async callbacks in sequenceWhich companies ask this question comes with the courseMedium15–25 min
- 12.2Run async callbacks in parallel and collect the results in orderWhich companies ask this question comes with the courseMedium15–25 min
- 12.3Promisify a callback APIWhich companies ask this question comes with the courseEasy10–15 min
- 12.4Promisify with several results and a custom markerWhich companies ask this question comes with the courseMedium20–30 min
- 12.5Run three tasks in sequence: chaining, then async/awaitWhich companies ask this question comes with the courseEasy10–20 min
- 12.6Run a sequence that carries on after a failureWhich companies ask this question comes with the courseMedium15–25 min
- 12.7Map over items with an async functionWhich companies ask this question comes with the courseMedium20–30 min
- 12.8Print results in order as soon as each is readyWhich companies ask this question comes with the courseMedium20–30 min
- 12.9First result within a time limit, success or failureWhich companies ask this question comes with the courseMedium15–25 min
- 12.10Merge the results of several promisesWhich companies ask this question comes with the courseMedium20–30 min
- 12.11Predict the output of eight async snippetsWhich companies ask this question comes with the courseMedium20–30 min
- 12.12Run an array of promise-returning functions in sequenceWhich companies ask this question comes with the courseEasy10–15 min
13Promise from scratch12 questions
- 13.1Promise.resolve and Promise.rejectWhich companies ask this question comes with the courseEasy10–20 min
- 13.2Promise.allWhich companies ask this question comes with the courseMedium15–30 min
- 13.3Promise.allSettledWhich companies ask this question comes with the courseMedium15–30 min
- 13.4Promise.raceWhich companies ask this question comes with the courseEasy10–20 min
- 13.5Promise.any with AggregateErrorWhich companies ask this question comes with the courseMedium15–30 min
- 13.6Promise.withResolvers and Promise.tryWhich companies ask this question comes with the courseEasy10–20 min
- 13.7A Promise: states and resolve onceWhich companies ask this question comes with the courseMedium15–30 min
- 13.8A Promise: then chaining and handler timingWhich companies ask this question comes with the courseHard30–50 min
- 13.9A Promise: catch and recoveryWhich companies ask this question comes with the courseHard30–50 min
- 13.10A Promise: finally that keeps the resultWhich companies ask this question comes with the courseHard30–50 min
- 13.11A Promise: adopting thenablesWhich companies ask this question comes with the courseHard30–50 min
- 13.12A Promise that passes the full spec testsWhich companies ask this question comes with the courseHard45–90 min
14Timeouts, retries and concurrency12 questions
- 14.1Reject a promise after a time limitWhich companies ask this question comes with the courseEasy10–15 min
- 14.2Fetch with a timeout and cancellationWhich companies ask this question comes with the courseMedium20–30 min
- 14.3Ignore stale responses (latest request wins)Which companies ask this question comes with the courseMedium20–30 min
- 14.4Retry with exponential backoffWhich companies ask this question comes with the courseMedium20–30 min
- 14.5A circuit breakerWhich companies ask this question comes with the courseHard35–50 min
- 14.6A retry budget shared by many callersWhich companies ask this question comes with the courseHard35–50 min
- 14.7Map with a concurrency limitWhich companies ask this question comes with the courseMedium20–30 min
- 14.8A rate limiter (n calls per second)Which companies ask this question comes with the courseMedium20–30 min
- 14.9Run tasks in dependency orderWhich companies ask this question comes with the courseMedium20–30 min
- 14.10Batch requests by size or by timeWhich companies ask this question comes with the courseMedium20–30 min
- 14.11Share one request between identical callersWhich companies ask this question comes with the courseMedium20–30 min
- 14.12Order package builds by their dependenciesWhich companies ask this question comes with the courseHard35–50 min
15Debounce and throttle6 questions
- 15.1DebounceWhich companies ask this question comes with the courseMedium15–25 min
- 15.2Debounce with leading edge, maxWait, cancel and flushWhich companies ask this question comes with the courseHard40–60 min
- 15.3Debounce a search inputWhich companies ask this question comes with the courseEasy15–20 min
- 15.4ThrottleWhich companies ask this question comes with the courseMedium15–25 min
- 15.5Throttle with leading and trailing optionsWhich companies ask this question comes with the courseHard30–45 min
- 15.6Choose debounce or throttle for six inputsWhich companies ask this question comes with the courseEasy15–20 min
16DOM: finding elements12 questions
- 16.1Ways to select and loop over elementsWhich companies ask this question comes with the courseEasy10–20 min
- 16.2Implement Element.closestWhich companies ask this question comes with the courseEasy10–15 min
- 16.3Implement Node.containsWhich companies ask this question comes with the courseEasy10–15 min
- 16.4Implement getRootNodeWhich companies ask this question comes with the courseEasy10–20 min
- 16.5Implement getElementsByTagNameWhich companies ask this question comes with the courseMedium15–25 min
- 16.6Implement getElementsByClassNameWhich companies ask this question comes with the courseMedium15–25 min
- 16.7Find elements by computed styleWhich companies ask this question comes with the courseMedium20–30 min
- 16.8Find elements by a tag pathWhich companies ask this question comes with the courseHard30–45 min
- 16.9Find the matching node in an identical treeWhich companies ask this question comes with the courseMedium15–25 min
- 16.10Are two DOM trees identical?Which companies ask this question comes with the courseMedium20–30 min
- 16.11Depth of a DOM tree, its unique tags and duplicate idsWhich companies ask this question comes with the courseMedium15–25 min
- 16.12Build a table of contents from headingsWhich companies ask this question comes with the courseMedium25–40 min
17DOM: changing the page and events12 questions
- 17.1Get and set inline styles with one helperWhich companies ask this question comes with the courseEasy10–20 min
- 17.2Add, remove and toggle classesWhich companies ask this question comes with the courseEasy15–25 min
- 17.3Build a class string from conditionsWhich companies ask this question comes with the courseEasy10–20 min
- 17.4Build class names from variant optionsWhich companies ask this question comes with the courseMedium20–35 min
- 17.5Insert, move and replace nodes with fragments and templatesWhich companies ask this question comes with the courseMedium20–35 min
- 17.6Render DOM from a tree descriptionWhich companies ask this question comes with the courseMedium25–40 min
- 17.7Read the text between two nodesWhich companies ask this question comes with the courseHard35–60 min
- 17.8Event delegation for a listWhich companies ask this question comes with the courseEasy10–20 min
- 17.9Stop propagation, prevent default and listen onceWhich companies ask this question comes with the courseEasy15–25 min
- 17.10Validate a field on focus and blurWhich companies ask this question comes with the courseEasy15–25 min
- 17.11Dispatch and listen for a custom eventWhich companies ask this question comes with the courseEasy15–25 min
- 17.12Keyboard shortcuts with modifiersWhich companies ask this question comes with the courseMedium25–40 min
18URLs, storage and safe HTML7 questions
- 18.1URLSearchParams from scratchWhich companies ask this question comes with the courseMedium25–40 min
- 18.2localStorage with expiryWhich companies ask this question comes with the courseEasy15–25 min
- 18.3Two-way binding between an input and an objectWhich companies ask this question comes with the courseMedium20–30 min
- 18.4Extract the links from an HTML stringWhich companies ask this question comes with the courseMedium15–25 min
- 18.5Sanitize HTML to an allowlistWhich companies ask this question comes with the courseHard40–60 min
- 18.6Choose safe DOM output for untrusted textWhich companies ask this question comes with the courseEasy15–20 min
- 18.7Keep return addresses on your own siteWhich companies ask this question comes with the courseMedium15–25 min
19Events, state and history14 questions
- 19.1An event emitterWhich companies ask this question comes with the courseMedium20–35 min
- 19.2Publish and subscribeWhich companies ask this question comes with the courseEasy10–20 min
- 19.3An observable with map and filterWhich companies ask this question comes with the courseHard35–60 min
- 19.4Record console.log historyWhich companies ask this question comes with the courseEasy10–20 min
- 19.5A Redux-style storeWhich companies ask this question comes with the courseMedium20–35 min
- 19.6Store middlewaresWhich companies ask this question comes with the courseMedium20–35 min
- 19.7Reactive state that tracks what it readsWhich companies ask this question comes with the courseHard35–60 min
- 19.8Undo and redoWhich companies ask this question comes with the courseMedium20–35 min
- 19.9A key-value store with undoWhich companies ask this question comes with the courseMedium20–35 min
- 19.10A map that remembers past valuesWhich companies ask this question comes with the courseMedium20–35 min
- 19.11Update an object immutably with commandsWhich companies ask this question comes with the courseMedium20–35 min
- 19.12An array whose methods never mutateWhich companies ask this question comes with the courseMedium20–35 min
- 19.13Apply a JSON PatchWhich companies ask this question comes with the courseHard40–60 min
- 19.14Produce immutable updates from a draftWhich companies ask this question comes with the courseHard45–60 min
20Caches and buffers4 questions
- 20.1A circular bufferWhich companies ask this question comes with the courseEasy15–25 min
- 20.2A cache with time to liveWhich companies ask this question comes with the courseMedium20–30 min
- 20.3An LRU cacheWhich companies ask this question comes with the courseMedium20–35 min
- 20.4An LFU cache, compared with LRUWhich companies ask this question comes with the courseHard35–50 min
21Recursion and nested data14 questions
- 21.1Flatten an array to any depth, recursively and with a stackWhich companies ask this question comes with the courseEasy15–25 min
- 21.2Flatten tree records and keep each nodeWhich companies ask this question comes with the courseMedium20–30 min
- 21.3Print every key and value of a nested objectWhich companies ask this question comes with the courseEasy15–25 min
- 21.4Deep clone with cycles, Dates, Maps and SetsWhich companies ask this question comes with the courseMedium25–40 min
- 21.5Deep equalWhich companies ask this question comes with the courseMedium25–40 min
- 21.6Deep mergeWhich companies ask this question comes with the courseMedium20–35 min
- 21.7Deep map and deep omitWhich companies ask this question comes with the courseMedium20–35 min
- 21.8Convert every key to camelCaseWhich companies ask this question comes with the courseEasy15–25 min
- 21.9Remove falsy values at every depthWhich companies ask this question comes with the courseEasy10–20 min
- 21.10Merge records for the same userWhich companies ask this question comes with the courseMedium20–35 min
- 21.11Get a value by pathWhich companies ask this question comes with the courseEasy10–20 min
- 21.12Set a value by path, creating what is missingWhich companies ask this question comes with the courseMedium20–35 min
- 21.13Flatten a nested object to dotted keys, and backWhich companies ask this question comes with the courseMedium25–40 min
- 21.14Block prototype pollution in nested writesWhich companies ask this question comes with the courseMedium25–40 min
22Serialization7 questions
- 22.1Implement JSON.stringifyWhich companies ask this question comes with the courseHard40–70 min
- 22.2Stringify without the password fieldWhich companies ask this question comes with the courseEasy10–20 min
- 22.3Detect a circular referenceWhich companies ask this question comes with the courseMedium15–30 min
- 22.4Remove circular referencesWhich companies ask this question comes with the courseMedium15–30 min
- 22.5Serialize Dates, Maps and Sets to JSON and backWhich companies ask this question comes with the courseHard30–50 min
- 22.6Serialize a DOM tree to HTMLWhich companies ask this question comes with the courseMedium20–35 min
- 22.7Compare structuredClone with JSON copyingWhich companies ask this question comes with the courseEasy10–20 min
23Text processing and interpreters8 questions
- 23.1Select and filter fields from recordsWhich companies ask this question comes with the courseEasy10–20 min
- 23.2A template engine with {{ }}Which companies ask this question comes with the courseMedium15–30 min
- 23.3A template engine with loops and conditionsWhich companies ask this question comes with the courseHard30–50 min
- 23.4Highlight search matches in textWhich companies ask this question comes with the courseMedium15–30 min
- 23.5Apply style ranges to textWhich companies ask this question comes with the courseMedium15–30 min
- 23.6Rich text to HTMLWhich companies ask this question comes with the courseHard30–50 min
- 23.7Sort page blocks into reading orderWhich companies ask this question comes with the courseHard30–50 min
- 23.8Interpret turtle drawing commandsWhich companies ask this question comes with the courseMedium15–30 min
24Build a small library10 questions
- 24.1AssertionsWhich companies ask this question comes with the courseEasy15–25 min
- 24.2A test runner (describe, it, hooks)Which companies ask this question comes with the courseMedium35–50 min
- 24.3An async test runner with timeouts and a reportWhich companies ask this question comes with the courseHard45–70 min
- 24.4A schema validatorWhich companies ask this question comes with the courseMedium30–45 min
- 24.5A schema validator with nested objects and custom messagesWhich companies ask this question comes with the courseHard50–75 min
- 24.6A chainable SQL query builderWhich companies ask this question comes with the courseMedium30–45 min
- 24.7An in-memory model layer with relationsWhich companies ask this question comes with the courseHard50–75 min
- 24.8A spreadsheet with formulas and dependenciesWhich companies ask this question comes with the courseHard60–90 min
- 24.9An API client with interceptors and typed errorsWhich companies ask this question comes with the courseMedium40–60 min
- 24.10Build and parse API requestsWhich companies ask this question comes with the courseMedium35–50 min
25Memory and cleanup4 questions
- 25.1Dispose listeners and subscriptions togetherWhich companies ask this question comes with the courseEasy15–25 min
- 25.2Store data per DOM element without leaksWhich companies ask this question comes with the courseMedium15–25 min
- 25.3A node registry with WeakRef and FinalizationRegistryWhich companies ask this question comes with the courseHard30–45 min
- 25.4Find and fix the leak in a view that closesWhich companies ask this question comes with the courseMedium20–30 min
26Accessibility3 questions
- 26.1Trap focus inside a dialogWhich companies ask this question comes with the courseMedium25–35 min
- 26.2A toolbar with a roving tabindexWhich companies ask this question comes with the courseMedium20–30 min
- 26.3Announce changes with a live regionWhich companies ask this question comes with the courseEasy15–20 min