HireHireInterview Quizzes › Frontend Developer

Frontend Developer Interview Questions

Think you're ready? These are the questions that actually decide Frontend Developer interviews. Warm up on Easy — then face the Hard round, where 95% of candidates crumble. 30 questions across 3 levels, instant score, completely free.

30Questions
3Difficulty levels
95%Fail the hard round
FreeInstant score
Easy
Warm-up · 10 Qs
Medium
Practical · 10 Qs
Hard
Brutal · 10 Qs
⚡ Take the Frontend Developer quiz — get your score →

The Frontend Developer interview questions

Below are the real questions, grouped by difficulty. Expand any one to reveal the correct answer and why — or take the timed quiz for a score you can share. Can you clear the Hard round?

Easy round 10 questions

In CSS, what is the difference between `display: none` and `visibility: hidden`?
  • A. Both remove the element from the layout flow entirely
  • B. `display: none` removes the element from the layout; `visibility: hidden` hides it but keeps its space ✓
  • C. `visibility: hidden` removes the element from the DOM; `display: none` keeps it
  • D. Both keep the element's space but only hide it visually
Correct answer: B. `display: none` takes the element out of the document flow (no space reserved), while `visibility: hidden` hides it but still reserves its space in the layout.
What does the CSS `box-sizing: border-box` property do to an element's width calculation?
  • A. Width includes only the content, excluding padding and border
  • B. Width includes content, padding, and border ✓
  • C. Width includes content and margin but not padding
  • D. Width is calculated as content plus margin plus border
Correct answer: B. With `border-box`, the specified width includes the content, padding, and border, making layouts more predictable.
In JavaScript, what is the result of `console.log(typeof null)`?
  • A. "null"
  • B. "undefined"
  • C. "object" ✓
  • D. "number"
Correct answer: C. `typeof null` returns "object", a long-standing quirk of JavaScript kept for backward compatibility.
What is the difference between `let` and `var` in JavaScript?
  • A. `let` is function-scoped while `var` is block-scoped
  • B. `let` is block-scoped while `var` is function-scoped ✓
  • C. Both are block-scoped but `var` cannot be reassigned
  • D. `let` is hoisted and initialized while `var` is not hoisted at all
Correct answer: B. `let` declarations are block-scoped (limited to the nearest enclosing block), whereas `var` is function-scoped.
In React, why should you provide a `key` prop when rendering a list of elements?
  • A. It sets the CSS styling order of the list items
  • B. It helps React identify which items changed, were added, or removed for efficient re-rendering ✓
  • C. It is required to pass data from parent to child components
  • D. It automatically sorts the list items alphabetically
Correct answer: B. Keys give elements a stable identity so React's reconciliation can efficiently track additions, removals, and reorders.
What does the `useEffect` hook with an empty dependency array `[]` do in a React function component?
  • A. It runs after every render of the component
  • B. It runs only once, after the initial render (on mount) ✓
  • C. It never runs because the array is empty
  • D. It runs before the component renders for the first time
Correct answer: B. An empty dependency array tells React to run the effect only once, after the component mounts.
In JavaScript, what will `console.log(0.1 + 0.2 === 0.3)` output?
  • A. true
  • B. false ✓
  • C. It throws a syntax error
  • D. undefined
Correct answer: B. Due to IEEE 754 floating-point representation, `0.1 + 0.2` equals `0.30000000000000004`, so the comparison is false.
Which HTTP method is idempotent and typically used to retrieve data without modifying server state?
  • A. POST
  • B. GET ✓
  • C. PATCH
  • D. DELETE
Correct answer: B. GET is a safe, idempotent method used to retrieve resources without causing side effects on the server.
What is event delegation in JavaScript?
  • A. Attaching a separate event listener to every child element individually
  • B. Attaching one listener to a parent element and using event bubbling to handle events from children ✓
  • C. Preventing events from bubbling up the DOM tree
  • D. Delegating event handling to a Web Worker thread
Correct answer: B. Event delegation attaches a single listener to a parent and leverages event bubbling to handle events from its child elements.
In CSS Flexbox, what does `justify-content: space-between` do to flex items along the main axis?
  • A. Places equal space around each item including the edges
  • B. Distributes items with the first at the start, the last at the end, and equal space between them ✓
  • C. Centers all items with no space between them
  • D. Stacks all items at the start of the container
Correct answer: B. `space-between` puts the first item at the start and last at the end, distributing remaining space evenly between items with no space at the edges.

Medium round 10 questions

You have a flex container with `display: flex` and three child items. You want the items to wrap onto multiple lines when they don't fit in one row. Which property do you add to the container?
  • A. flex-direction: column
  • B. flex-wrap: wrap ✓
  • C. align-items: stretch
  • D. justify-content: space-between
Correct answer: B. flex-wrap: wrap allows flex items to break onto multiple lines when they exceed the container width.
In JavaScript, what will `console.log(0.1 + 0.2 === 0.3)` output, and why?
  • A. true, because the sum equals 0.3 exactly
  • B. false, because floating-point arithmetic introduces small rounding errors ✓
  • C. true, because JavaScript rounds automatically
  • D. It throws a TypeError
Correct answer: B. IEEE 754 floating-point representation makes 0.1 + 0.2 evaluate to 0.30000000000000004, so the strict comparison is false.
In React, you render a list with `items.map(item => <li>{item.name}</li>)` and see a console warning. What is the correct fix?
  • A. Wrap the list in a Fragment
  • B. Add a unique `key` prop to each <li> ✓
  • C. Use a for loop instead of map
  • D. Move the map call into useEffect
Correct answer: B. React requires a stable, unique `key` on each list element so it can efficiently track and reconcile items.
Which CSS unit is relative to the root element's font size, making it useful for consistent scaling regardless of nested parent font sizes?
  • A. em
  • B. rem ✓
  • C. px
  • D. vh
Correct answer: B. rem is always relative to the root (html) element's font size, unlike em which compounds relative to the parent.
You need to make an AJAX request and handle the response. Which approach correctly handles a failed fetch (e.g., network error)?
  • A. fetch(url).then(res => res.json()).catch(err => handle(err)) ✓
  • B. fetch(url).json().then(data => ...)
  • C. fetch(url, { catch: handle })
  • D. try { fetch(url) } catch(e) { handle(e) } with no await
Correct answer: A. fetch returns a promise, so .then chains parse the response and .catch handles network-level rejections.
In the CSS box model with `box-sizing: border-box`, if an element has `width: 200px; padding: 20px; border: 5px solid`, what is its total rendered width?
  • A. 250px
  • B. 230px
  • C. 200px ✓
  • D. 210px
Correct answer: C. With border-box, padding and border are included inside the declared width, so the total stays 200px.
What is the difference between `==` and `===` in JavaScript?
  • A. === compares values, == compares references
  • B. == performs type coercion before comparing, === requires same type and value ✓
  • C. They are identical in behavior
  • D. == is only for numbers, === is only for strings
Correct answer: B. == coerces operands to a common type before comparing, while === checks both type and value without coercion.
You want a click handler on a parent element to also catch clicks on dynamically added child buttons. Which technique achieves this efficiently?
  • A. Adding a listener to each button individually after creation
  • B. Event delegation: one listener on the parent using event.target ✓
  • C. Using inline onclick attributes
  • D. Wrapping each button in its own iframe
Correct answer: B. Event delegation attaches a single listener to a parent and inspects event.target, so it works for current and future child elements.
In Git, you committed to the wrong branch and want to move your last commit to a new branch without losing work. Which sequence works?
  • A. git branch newbranch; git reset --hard HEAD~1 on the current branch, then git checkout newbranch ✓
  • B. git push --force to overwrite history
  • C. git commit --amend on both branches
  • D. git stash pop twice
Correct answer: A. Creating the new branch preserves the commit, then resetting the original branch back one commit removes it from there while keeping it on newbranch.
Which HTML approach is the most semantically correct and accessible for a site's primary navigation menu?
  • A. A <div class="nav"> containing <span> links
  • B. A <nav> element containing a <ul> of <li> with <a> links ✓
  • C. A <table> with one row of links
  • D. A series of <button> elements with onclick redirects
Correct answer: B. The <nav> landmark with a list of anchor links is semantic and communicates navigation structure to assistive technology.

Hard round 10 questions

Consider this code: ```js console.log('A'); setTimeout(() => console.log('B'), 0); Promise.resolve().then(() => console.log('C')).then(() => console.log('D')); queueMicrotask(() => console.log('E')); console.log('F'); ``` What is the exact console output order?
  • A. A F C E D B ✓
  • B. A F B C E D
  • C. A F C D E B
  • D. A F E C D B
Correct answer: A. Synchronous logs (A, F) run first, then all microtasks in enqueue order (C and E queued before D, which is chained after C), then the setTimeout macrotask (B).
A component list re-renders every item on each parent update despite `React.memo` on the child. The parent passes `onSelect={() => handle(id)}` and `style={{ margin: 4 }}` as props. Why does memo fail, and what is the minimal correct fix?
  • A. memo does a deep comparison that is too slow; switch to useMemo on the whole list
  • B. The inline arrow and object literal create new references each render, breaking memo's shallow prop check; memoize the callback with useCallback and hoist/memoize the style object ✓
  • C. React.memo only works on class components; convert children to PureComponent
  • D. memo ignores function props by design; wrap the child in useTransition
Correct answer: B. React.memo does a shallow reference comparison, and new inline function/object literals produce fresh references every render, so stabilizing them with useCallback and a memoized/constant style restores memoization.
You implement a trailing-edge debounce. A user types 5 characters within the wait window, then stops. With a correct trailing-only debounce (wait=300ms), how many times does the wrapped function execute and with which argument?
  • A. 5 times, once per keystroke
  • B. 1 time, with the argument from the last (5th) call ✓
  • C. 1 time, with the argument from the first call
  • D. 2 times: once leading, once trailing
Correct answer: B. A trailing debounce resets its timer on every call and only fires once after activity stops, invoking the function with the most recent arguments captured at the last call.
This custom hook has a bug: ```js function useInterval(callback, delay) { useEffect(() => { const id = setInterval(() => callback(), delay); return () => clearInterval(id); }, [delay]); } ``` What happens and why?
  • A. It leaks intervals because the cleanup never runs
  • B. The interval always invokes the callback captured on the first render with the delay, causing a stale-closure bug because callback is not in the deps and not stored in a ref ✓
  • C. It throws because callback is a function and cannot be a dependency
  • D. It re-creates the interval on every render, causing excessive timers
Correct answer: B. Because `callback` is omitted from the dependency array, the interval closes over the first render's callback and keeps calling that stale version; the standard fix stores callback in a ref updated each render.
In React 18 concurrent rendering, you wrap a state update that filters a large list in `startTransition`, while the text input's own `setState` stays outside it. What behavior does this specifically produce?
  • A. The input update is delayed so both stay in sync
  • B. The urgent input update stays responsive and can interrupt/preempt the in-progress non-urgent list render, which React may throw away and restart ✓
  • C. Both updates are batched into a single synchronous commit
  • D. The list update runs on a Web Worker off the main thread
Correct answer: B. Transitions mark the list update as interruptible/non-urgent, so a higher-priority input update can preempt the in-progress render, keeping typing responsive while React discards and restarts the stale transition render.
Predict the output: ```js const obj = { val: 42, getVal: function () { return (() => this.val)(); }, getValBad: function () { return function () { return this.val; }(); } }; console.log(obj.getVal()); console.log(obj.getValBad()); ``` (non-strict mode)
  • A. 42 then 42
  • B. 42 then undefined ✓
  • C. undefined then undefined
  • D. 42 then throws TypeError
Correct answer: B. The arrow function lexically inherits `this` from getVal (obj), returning 42, while the plain IIFE is called as a standalone function so its `this` is the global object, whose `val` is undefined.
For an image-heavy product landing page, LCP is 4.1s. The LCP element is a hero `<img>` loaded via a JS component after hydration. Which single change most directly improves LCP?
  • A. Add `loading="lazy"` to the hero image
  • B. Server-render the hero `<img>` in the initial HTML with `fetchpriority="high"` and a preload, so it isn't blocked on JS/hydration ✓
  • C. Convert the whole page to client-side rendering to reduce TTFB
  • D. Wrap the hero component in React.lazy and Suspense
Correct answer: B. LCP is delayed because the largest element is discovered only after JS runs; emitting the image in the initial HTML with high fetch priority/preload lets the browser start the download immediately during the critical rendering path.
Two independently deployed micro-frontends via Webpack Module Federation both list React as a shared singleton but pin different minor versions. At runtime a hook throws "Invalid hook call." What is the root cause?
  • A. Module Federation cannot share React at all
  • B. With `singleton: true` but incompatible `requiredVersion` ranges, two React copies get loaded, so components and the reconciler use different React instances/dispatchers ✓
  • C. React hooks are globally disabled in federated modules
  • D. The shell must re-export React from a CDN for singletons to work
Correct answer: B. A hook call needs one React instance; when version ranges don't satisfy the singleton constraint, Webpack loads a second React copy, splitting the internal dispatcher and triggering the invalid-hook-call error.
What does this TypeScript evaluate `T` to? ```ts type Unwrap<T> = T extends Promise<infer U> ? Unwrap<U> : T; type T = Unwrap<Promise<Promise<string>>>; ```
  • A. Promise<string>
  • B. Promise<Promise<string>>
  • C. string ✓
  • D. unknown
Correct answer: C. The conditional type recursively unwraps nested Promises using `infer`, so both Promise layers are stripped, leaving `string`.
With TanStack Query, you do an optimistic update in `onMutate`, then the mutation fails on the server. To correctly restore prior UI, what must `onMutate`/`onError` do?
  • A. Nothing; React Query auto-rolls back all optimistic writes
  • B. In onMutate, cancel in-flight queries, snapshot the previous cache value, and write the optimistic value; in onError, restore that snapshot; then invalidate in onSettled ✓
  • C. Call queryClient.clear() in onError to wipe stale data
  • D. Set staleTime to 0 so the failed value auto-corrects on next render
Correct answer: B. React Query does not auto-rollback manual cache writes; the correct pattern cancels outgoing refetches, snapshots the previous value for restoration on error, and revalidates on settle.

Prep for another role

Questions are original, written and independently verified for HireHire's role interview quizzes. They reflect the kind of knowledge Frontend Developer interviews test, not any specific company's questions. HireHire maps live tech & IT jobs across India, updated regularly. Last updated: July 2026.