Frontend Developer Interview Questions and Answers

Frontend interviews go deeper than general web roles. Expect questions on how JavaScript actually runs, how the browser renders, how React decides what to update, and how you measure and fix performance. The last section covers the frontend system design questions now common at mid and senior level.

54 questions with answersLevels: Fresher to SeniorUpdated November 2026

JavaScript internals

The language questions that filter most candidates.

Q1.Explain the event loop.

JavaScript runs on one thread with a call stack. Async callbacks wait in queues. When the stack is empty, the event loop first runs all microtasks (promise callbacks, queueMicrotask), then takes the next macrotask (timers, I/O, events), and the browser may render between tasks.

Q2.What is the output order of a setTimeout and a resolved Promise logged after synchronous code?

Synchronous logs come first, then the promise callback because it is a microtask, then the setTimeout callback because it is a macrotask, even with a 0 ms delay.

Q3.What is hoisting?

Declarations are processed before code runs. Function declarations are fully hoisted. var declarations are hoisted and set to undefined. let, const and class are hoisted but cannot be accessed until their line runs, the temporal dead zone.

Q4.What is a closure and give a practical use.

A closure is a function that keeps access to variables from its outer scope after that scope returns. It is used for private state, factory functions, memoisation, and functions like debounce that need to remember a timer.

Q5.How does this work in JavaScript?

It depends on how a function is called: the object before the dot for method calls, undefined in strict mode for plain calls, the new object with new, and the bound value with call, apply or bind. Arrow functions do not have their own this; they take it from the surrounding scope.

Q6.What is prototypal inheritance?

Objects link to a prototype object. When a property is not found on the object, JavaScript looks up the prototype chain. Classes are syntax over this mechanism.

Q7.What is the difference between shallow and deep copy?

A shallow copy, like spread or Object.assign, copies top-level properties, so nested objects are shared. A deep copy duplicates everything. structuredClone() makes deep copies of most data types.

Q8.What is the difference between debounce and throttle?

Debounce waits until calls stop for a set time, then runs once, which suits search inputs. Throttle runs at most once per interval while calls continue, which suits scroll and resize handlers.

Q9.What are Promise.all, allSettled, race and any?

all resolves when all succeed and rejects on the first failure. allSettled waits for all and reports each result. race settles with the first to settle. any resolves with the first success and rejects only if all fail.

Q10.What are ES modules?

The standard module system using import and export. They are statically analysable, which enables tree shaking, run in strict mode and load asynchronously in the browser with type=module.

Q11.What is the difference between null and undefined?

undefined means a value was never assigned. null is an explicit empty value set by the developer. typeof null returns object due to a historical bug.

Q12.What are WeakMap and WeakSet for?

They hold object keys weakly, so entries do not stop garbage collection. They are useful for caching data about DOM nodes or objects without causing memory leaks.

Q13.How does TypeScript help on a frontend team?

It catches type errors at build time, documents component props and API shapes, and makes refactoring safer. Generics, union types and narrowing let you model UI states precisely.

Q14.What is the difference between map, filter and reduce?

map returns a new array with each item transformed, filter returns the items that pass a test, and reduce combines all items into one value such as a total or a grouped object. None of them change the original array.

Q15.What is optional chaining and nullish coalescing?

a?.b?.c returns undefined instead of throwing when something in the chain is null or undefined. x ?? 'default' uses the default only for null or undefined, unlike ||, which also replaces 0 and empty strings.

Browser and rendering

How pages get from bytes to pixels.

Q16.What is the critical rendering path?

The steps from HTML to pixels: parse HTML into the DOM, parse CSS into the CSSOM, combine them into the render tree, calculate layout, paint and composite layers. CSS blocks rendering and synchronous scripts block parsing.

Q17.What is the difference between reflow and repaint?

Reflow, or layout, recalculates sizes and positions and is expensive. Repaint redraws pixels without changing layout. Changing transform and opacity can skip both and run on the compositor.

Q18.What is layout thrashing?

Reading layout values like offsetHeight right after writing styles in a loop, which forces repeated synchronous layouts. Fix it by batching reads before writes or using requestAnimationFrame.

Q19.What is the difference between async and defer on script tags?

Both download without blocking parsing. async runs as soon as it downloads, in any order. defer runs in order after the HTML is parsed, so it suits most app scripts.

Q20.What do preload, prefetch and preconnect do?

preload fetches a resource needed for the current page early, such as the LCP image or a font. prefetch fetches something likely needed for the next navigation at low priority. preconnect opens the connection to another origin early.

Q21.How do you improve Largest Contentful Paint?

Speed up server response, preload the LCP image with fetchpriority high, serve it in a modern format at the right size, avoid lazy-loading it, remove render-blocking CSS and JS, and server-render the main content.

Q22.How do you improve Interaction to Next Paint?

Break long tasks into smaller ones, yield to the main thread with scheduler.yield or setTimeout, reduce JavaScript, avoid heavy work in event handlers and keep re-renders small.

Q23.How do you prevent layout shift?

Set width and height or aspect-ratio on images and embeds, reserve space for ads and banners, avoid inserting content above existing content and use font-display with size-adjusted fallbacks.

Q24.What is a Web Worker?

A script running on a background thread with no DOM access. It communicates by postMessage and is used for heavy computation such as parsing large files without blocking the UI.

Q25.What is a Service Worker?

A script that sits between the page and the network. It enables offline support, caching strategies, background sync and push notifications, and is the base of Progressive Web Apps.

React and frameworks

The library most frontend jobs ask about.

Q26.How does React decide what to update?

When state changes, React re-renders the component and its children to produce a new element tree, compares it with the previous one (reconciliation) and applies only the differences to the DOM.

Q27.Why do list items need keys?

Keys let React match items between renders. Without stable keys, or with array indexes on lists that reorder, React can reuse the wrong component state and inputs show the wrong values.

Q28.What causes a component to re-render?

Its state changes, its parent re-renders, or a context it uses changes. Props changing is not required; a parent re-render re-renders children unless they are memoised.

Q29.What are the rules of hooks?

Call hooks only at the top level of a function component or custom hook, never inside conditions, loops or nested functions, so React can match hook state by call order.

Q30.When should you not use useEffect?

For deriving data from props or state, which can be computed during render, and for handling user events, which belong in event handlers. Effects are for synchronising with external systems.

Q31.What is the difference between controlled and uncontrolled inputs?

A controlled input gets its value from React state and updates it on change. An uncontrolled input keeps its own value in the DOM, read with a ref or form data. Form actions in React 19 work well with uncontrolled inputs.

Q32.What does the React Compiler do?

It automatically memoises components and values at build time, so in many cases you no longer need manual useMemo, useCallback and React.memo. Code must follow the rules of React for it to work.

Q33.What are React Server Components?

Components that run only on the server, can read data directly and send no JavaScript to the browser. Client Components, marked with use client, handle interactivity. Next.js App Router uses this model.

Q34.What is hydration and what causes hydration errors?

Hydration attaches event handlers to server-rendered HTML. Errors happen when the client's first render differs from the server HTML, for example from dates, random values or browser-only APIs during render.

Q35.What is the difference between SSR, SSG and ISR?

SSR renders HTML on each request. SSG renders at build time. ISR serves static pages and regenerates them in the background after a set time or on demand.

Q36.How do you manage server state in React?

With a data library like TanStack Query or SWR, which handles caching, deduplication, background refetching and stale data, or with server components and framework data loaders.

Q37.What is code splitting?

Breaking the bundle into chunks loaded on demand with dynamic import and React.lazy, usually by route, so users download only what the current page needs.

Q38.When would you use useReducer instead of useState?

When state has several related fields or the next state depends on the previous one in complex ways, such as a multi-step form. A reducer keeps all transitions in one testable function.

Q39.What problem does Context solve and what is its downside?

Context passes values deep into the tree without prop drilling. Every consumer re-renders when the value changes, so split contexts by concern and keep fast-changing state elsewhere.

CSS, accessibility and testing

Questions on quality and craft.

Q40.What is BEM and why use a naming convention?

Block, Element, Modifier naming such as card__title--large keeps class names predictable and avoids specificity fights. CSS Modules, utility classes like Tailwind and CSS-in-JS solve the same scoping problem differently.

Q41.What are container queries?

They style a component based on the size of its container rather than the viewport, so the same card can adapt in a sidebar or a main column.

Q42.What does the :has() selector do?

It selects an element based on its descendants or following elements, for example form:has(input:invalid). It acts like a long-requested parent selector.

Q43.What is ARIA and when should you use it?

ARIA attributes add roles, states and labels for assistive technology. The first rule is to use native HTML elements where possible; add ARIA only when building custom widgets, and test that keyboard behaviour matches the role.

Q44.How do you make a modal dialog accessible?

Use the native dialog element or role dialog with aria-modal, move focus into it on open, trap focus inside, close on Escape, return focus to the trigger on close and give it a label.

Q45.How do you test frontend code?

Unit tests with Vitest or Jest, component tests with Testing Library that query like a user, end-to-end tests with Playwright or Cypress, plus visual regression and accessibility checks in CI.

Q46.What are design tokens?

Named values for colours, spacing, typography and radii shared between design and code, often stored as JSON and exported to CSS variables, so a design system stays consistent across products.

Q47.What is the difference between visibility hidden, display none and the hidden attribute?

display none removes the element from layout and from the accessibility tree. visibility hidden keeps its space but hides it. The hidden attribute behaves like display none by default. For text only screen readers should hear, use a visually-hidden utility class.

Frontend system design

Senior-level open questions.

Q48.How would you design an autocomplete search box?

Debounce input, cancel stale requests with AbortController, cache recent results, show loading and empty states, support keyboard navigation with the combobox ARIA pattern, highlight matches and limit results. Measure how long results take to appear.

Q49.How would you build an infinite scrolling feed?

Use cursor-based pagination, an IntersectionObserver near the bottom to load more, list virtualisation for long lists, skeleton loaders, restoring scroll position on back navigation and a fallback load more button for accessibility.

Q50.How would you design a component library for several teams?

Start with tokens and accessible primitives, document components in Storybook, version with semantic versioning, write visual and interaction tests, support theming and publish to a private registry with a changelog.

Q51.How do you handle errors and loading states consistently?

Use error boundaries per route or section, a shared fetch layer that normalises errors, Suspense boundaries with skeletons, retry actions and logging to an error tracker with user context.

Q52.How would you approach a micro-frontend architecture?

Only when separate teams need independent deployment. Split by business domain, share a design system and a small shell, use Module Federation or route-level composition, and watch for duplicated dependencies and inconsistent UX.

Q53.A page scores 40 on Lighthouse mobile. What is your plan?

Check field data in Search Console or CrUX first, then the Lighthouse opportunities. Usually: fix the LCP image, cut unused JavaScript and third-party tags, split bundles, defer non-critical scripts, compress images and reduce long tasks. Re-measure after each change.

Q54.How would you add internationalisation to a large app?

Extract strings into message files with an i18n library such as react-intl, i18next or next-intl, format dates, numbers and plurals with the Intl API, support right-to-left layouts with logical CSS properties and load locale files on demand.

How to prepare for the interview

  • Practise writing debounce, throttle, a promise-based retry and a simple event emitter from memory.
  • Be able to explain the event loop with a small code example and its output order.
  • For system design, structure your answer: requirements, components, state, data fetching, performance, accessibility.
  • Bring numbers from a real project: bundle size, LCP or INP before and after a fix.