Technology interview questions hub
JavaScript Interview Questions for Frontend Interviews
Use this Javascript interview questions hub to practice coding and trivia leaves, then return to the master library and interview practice platform.
Practice snapshot
Focus by stack, not random tabs.
This hub keeps coding and trivia in one flow so implementation and explanation skills improve together.
Use this page as a planning surface for interview prep, not just a random question feed.
- Prioritize high-impact javascript coding prompts first.
- Use javascript trivia rounds to sharpen explanation speed.
- Escalate into the frontend interview prep platform for guided sequencing.
Coding challenges to start with
- Create a Counter Function
Support an optional initial value and keep the API simple so consumers can call inc/dec/get without exposing the internal state. Mention closure behavior, edge cases like negative increments, and tests for independent c…
Open challenge → - Sleep / Delay Promise
Implement sleep(ms) that returns a Promise resolving after ms milliseconds. Use it to pause async flows like retries, exponential backoff, UI delays, or test helpers without blocking the event loop or freezing the UI th…
Open challenge → - Add Two Promises
This is a small async composition task and should return a Promise that resolves to the numeric sum once both inputs settle successfully.
Open challenge → - Create a Deferred Promise (For Async Tests)
Implement createDeferred() to build a controllable Promise: { promise, resolve, reject }. This is a common testing tool to make async flows deterministic (you decide exactly when something resolves/rejects).
Open challenge → - Create a Spy Function (Test Double)
Implement createSpy(impl?) to produce a callable spy that records every call (args + this) and optionally delegates to an implementation. Spies are a core unit-testing tool to verify behavior at boundaries (network, sto…
Open challenge → - Custom setTimeout/clearTimeout Timer Manager
Build a timer registry with mySetTimeout, myClearTimeout, and myClearAllTimeouts. Return your own numeric ids, store native handles, and clean up on fire. Complexity: O(1) set/clear, O(k) for clearAll.
Open challenge → - Delegated Event Handler (E)
Implement `delegate(root, eventType, selector, handler)` for **event delegation**. Requirements: 1) Attach **one** event listener to `root`. 2) When an event fires, if `event.target` (or one of its ancestors up to `root…
Open challenge → - Event Emitter (Mini Implementation)
Build a tiny event emitter with on, off, and emit. Store listeners per event, allow multiple listeners, and ensure off removes only the specified handler without breaking others. This tests data structures and event flo…
Open challenge → - Implement Array.prototype.filter
Recreate the native `Array.prototype.filter()` method as `myFilter`. It should call a provided callback once for each existing element in the array, include the element in the new array if the callback returns a truthy…
Open challenge → - Implement Array.prototype.map
Recreate the native `.map()` method **without using it**. Your `myMap` must call `callbackFn(value, index, array)` for each **existing** index, bind `thisArg`, and return a new array with the **same length** where holes…
Open challenge → - Implement Array.prototype.reduce
Recreate the native `.reduce()` method **without using it**. Your `myReduce` must call the reducer with `(accumulator, currentValue, index, array)` only for existing indices, handle an optional `initialValue`, and retur…
Open challenge → - Implement Promise.all
Implement a function `promiseAll(promises)` that behaves like `Promise.all`. It should take an array of values or promises and return a single promise that resolves to an array of results, preserving order, or rejects a…
Open challenge →
Trivia questions for explanation speed
- What are callbacks in JavaScript?
A callback is a function passed as an argument to another function to be executed later, often after a task is completed. Covers: async, callbacks, event loop, functions, higher order functions.
Open question → - Async Race Conditions and Stale UI Updates
When multiple async requests are in flight, they can resolve out of order and overwrite newer UI state. Explain why this happens and how to prevent stale updates with cancellation or guards.
Open question → - DOM XSS Prevention in JavaScript: Dangerous Sinks, Safe APIs, and CSP
Security-focused frontend interview guide to DOM XSS: attacker-controlled sources, dangerous DOM sinks, safe rendering patterns, URL/protocol validation, and defense in depth with CSP and Trusted Types.
Open question → - Explain 'hoisting' in JavaScript
Hoisting is JavaScript’s default behavior of moving declarations to the top of their scope before code execution. In practice, it means you can use certain variables and functions before declaring them — but only partia…
Open question → - Explain Closures in JavaScript
A closure happens when a function keeps access to variables from its outer scope, even after that outer function has finished. It’s how JavaScript allows private data and persistent state inside functions.
Open question → - Explain Event Delegation in JavaScript
Event delegation is a technique where a single event listener on a parent element handles events for multiple child elements by using event bubbling and checking the event target. Edge cases include stopPropagation and…
Open question → - Explain Hoisting and the Temporal Dead Zone (TDZ)
During the creation phase, JavaScript moves declarations to the top of their scope (hoisting). However, variables declared with `let` and `const` exist in a 'temporal dead zone' until their declaration is reached, makin…
Open question → - Explain the `this` keyword in JavaScript
The value of `this` in JavaScript depends on how a function is called — not where it’s defined. It can refer to the global object, a specific object, or be `undefined` in strict mode or arrow functions. The value of thi…
Open question → - Explain the difference in hoisting between `var`, `let`, and `const`
All variable declarations are hoisted, but only `var` is initialized with `undefined`. Variables declared with `let` and `const` exist in the temporal dead zone until execution reaches their declaration, making them ina…
Open question → - How do you optimize a web page’s response or load time?
This question checks if you can reason about performance across the network, render pipeline, assets, and runtime. Interviewers expect concrete tactics like caching, compression, code splitting, and image optimization.
Open question → - Mutability vs Immutability in JavaScript (State, References, and Side Effects)
Mutable data can be changed in place, while immutable data is never modified — instead, new copies are created. Understanding this difference is critical for predictable state management in React, Angular, Redux/NgRx, a…
Open question → - Promise.all vs allSettled vs race vs any (JavaScript Promise Combinators)
Promise combinators coordinate multiple async operations. all fails fast, allSettled always returns results, race resolves/rejects with the first settled promise, and any resolves with the first fulfilled promise (or re…
Open question →
Complete the prep loop
After these JavaScript Interview Questions for Frontend Interviews drills, continue with frontend interview questions hub, then frontend interview preparation guides and frontend interview preparation tracks to keep your weekly plan structured.