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. 80 questions across 3 levels, instant score, completely free.

80Questions
3Difficulty levels
95%Fail the hard round
FreeInstant score
Easy
Warm-up · 20 Qs
Medium
Practical · 30 Qs
Hard
Brutal · 30 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 20 questions

A `<p class="note">` is styled by both `p { color: blue; }` and `.note { color: green; }` in the same stylesheet. What color is the text?
  • A. Blue, because the element rule comes first
  • B. Green, because a class selector outranks an element selector ✓
  • C. Black, because the two rules cancel each other out
  • D. Green, but only if `!important` is added
Correct answer: B. A class selector has higher specificity than a type selector, so `.note` wins.
On a flex container with `display: flex; justify-content: center;` (default row direction), how are the children positioned?
  • A. Centered vertically along the cross axis
  • B. Centered horizontally along the main axis ✓
  • C. Stretched to fill the full width
  • D. Pushed to the start of the row
Correct answer: B. `justify-content` aligns items along the main axis, which is horizontal for a row.
What does `console.log(typeof null)` print in JavaScript?
  • A. "null"
  • B. "object" ✓
  • C. "undefined"
  • D. "boolean"
Correct answer: B. `typeof null` returns "object", a long-standing quirk of the language.
Given `0 == '0'` and `0 === '0'`, what are the two results?
  • A. true and true
  • B. true and false ✓
  • C. false and false
  • D. false and true
Correct answer: B. `==` coerces the string to a number so it is true, while `===` checks type and is false.
An element has `width: 200px; padding: 20px; box-sizing: border-box;`. What is its total rendered width?
  • A. 240px, padding adds outside
  • B. 200px, padding is included in the width ✓
  • C. 220px, only one side counts
  • D. 180px, padding is subtracted twice
Correct answer: B. With `border-box`, padding is drawn inside the declared width, so total width stays 200px.
Clicking a `<button>` nested inside a `<div>`, both with click handlers and no `stopPropagation`, fires them in what order by default?
  • A. div handler first, then button handler
  • B. button handler first, then div handler ✓
  • C. Only the button handler fires
  • D. Both fire at the same instant with no order
Correct answer: B. Events bubble upward, so the target (button) handler runs before the ancestor (div).
What does `[1, 2, 3].map(n => n * 2)` evaluate to?
  • A. Mutates the array to [2, 4, 6] in place
  • B. Returns a new array [2, 4, 6] ✓
  • C. Returns the number 12
  • D. Returns undefined and logs each value
Correct answer: B. `map` returns a new array of transformed values and does not mutate the original.
In React, why should each item in a rendered list have a unique `key` prop?
  • A. It sets the CSS id used for styling
  • B. It helps React identify which items changed between renders ✓
  • C. It is required to make the list clickable
  • D. It stores the item's data in localStorage
Correct answer: B. Keys let React match elements across re-renders so it can update the DOM efficiently.
An element has `position: absolute; top: 0; left: 0;`. Relative to what is it positioned?
  • A. The browser viewport, always
  • B. The nearest ancestor with a non-static position ✓
  • C. Its immediate parent, regardless of that parent's position
  • D. The `<body>` element only
Correct answer: B. An absolutely positioned element is offset from its nearest positioned ancestor.
What is the difference between `display: none` and `visibility: hidden` for an element?
  • A. Both keep the element's space in the layout
  • B. `display: none` removes it from layout; `visibility: hidden` keeps its space ✓
  • C. `visibility: hidden` removes it from layout; `display: none` keeps its space
  • D. Neither affects layout; both only change opacity
Correct answer: B. `display: none` takes the element out of the flow, while `visibility: hidden` leaves an empty gap.
Using `var` in a `for` loop, `for (var i = 0; i < 3; i++) setTimeout(() => console.log(i));` logs what?
  • A. 0, 1, 2
  • B. 3, 3, 3 ✓
  • C. 0, 0, 0
  • D. 1, 2, 3
Correct answer: B. `var` is function-scoped, so all callbacks share one `i` that equals 3 after the loop ends.
Data saved with `sessionStorage.setItem(...)` behaves how when the user closes and reopens the tab?
  • A. It persists indefinitely like localStorage
  • B. It is cleared when the tab is closed ✓
  • C. It syncs to the server automatically
  • D. It is shared across every open tab
Correct answer: B. sessionStorage lives only for the tab's session and is wiped when that tab closes.
A `<img>` has no `alt` attribute and fails to load. What is the main problem for accessibility?
  • A. The image will load twice to retry
  • B. Screen reader users get no description of the image ✓
  • C. The browser blocks the whole page from rendering
  • D. The image is forced to grayscale
Correct answer: B. Without `alt`, assistive technology has no text to announce for the image.
Inside an object method, an arrow function used as a callback takes its `this` from where?
  • A. The object that owns the method
  • B. The surrounding lexical scope where it was defined ✓
  • C. The global `window` object always
  • D. The element that triggered the event
Correct answer: B. Arrow functions do not bind their own `this`; they inherit it from the enclosing scope.
The CSS unit `rem` is calculated relative to which font size?
  • A. The parent element's font size
  • B. The root (`<html>`) element's font size ✓
  • C. The nearest block element's font size
  • D. A fixed 12px in every browser
Correct answer: B. `rem` is relative to the root element's font size, unlike `em` which uses the parent.
`const user = { name: 'A' }; user.name = 'B';` — what happens?
  • A. A TypeError is thrown for reassigning a const
  • B. It succeeds; the object's property is mutated to 'B' ✓
  • C. The whole object is frozen and nothing changes
  • D. `user` becomes undefined
Correct answer: B. `const` prevents rebinding the variable, but the object it points to can still be mutated.
A `@media (max-width: 600px)` block applies its styles when?
  • A. Only on screens wider than 600px
  • B. When the viewport width is 600px or less ✓
  • C. Only when printing the page
  • D. On every screen regardless of width
Correct answer: B. `max-width: 600px` matches viewports up to and including 600px.
`document.querySelector('.card')` on a page with three elements of class `card` returns what?
  • A. An array of all three elements
  • B. The first matching element only ✓
  • C. A live NodeList of all matches
  • D. The last matching element
Correct answer: B. `querySelector` returns only the first element that matches; `querySelectorAll` returns all.
A search box calls an API on every keystroke and feels laggy. Which technique best reduces the number of calls?
  • A. Wrapping each call in a try/catch
  • B. Debouncing so the call fires only after typing pauses ✓
  • C. Adding `async` to the event handler
  • D. Caching the results in a cookie
Correct answer: B. Debouncing delays the call until input settles, cutting redundant requests while typing.
`const [a, b] = [10, 20, 30];` assigns what to `a` and `b`?
  • A. a = 10, b = 30
  • B. a = 10, b = 20 ✓
  • C. a = [10,20], b = 30
  • D. a = 20, b = 30
Correct answer: B. Array destructuring binds by position, so `a` gets 10, `b` gets 20, and 30 is ignored.

Medium round 30 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.
What is the main benefit of event delegation?
  • A. Attaching one listener on a parent to handle events from many children ✓
  • B. Completely preventing event bubbling
  • C. Running handlers inside a Web Worker
  • D. Deferring handlers until the browser is idle
Correct answer: A. Delegation leverages bubbling so a single parent listener manages events from many child elements.
How do debounce and throttle differ?
  • A. Debounce runs after activity stops; throttle runs at fixed intervals during activity ✓
  • B. Debounce runs at fixed intervals; throttle runs after activity stops
  • C. Both fire on every single event
  • D. Debounce cancels the event while throttle repeats it
Correct answer: A. Debounce waits for a pause in activity, while throttle caps execution to once per interval.
What is the specificity of the selector `#header .nav a`?
  • A. 0,1,1,1 ✓
  • B. 0,0,2,1
  • C. 0,1,2,0
  • D. 0,2,1,0
Correct answer: A. One ID, one class, and one element type give a specificity of (0,1,1,1).
When does `Promise.all` reject?
  • A. Only when every promise rejects
  • B. As soon as any single promise rejects ✓
  • C. It never rejects and collects the errors
  • D. Only after all promises have settled
Correct answer: B. `Promise.all` rejects immediately with the reason of the first promise that rejects.
What distinguishes sessionStorage from localStorage?
  • A. sessionStorage is cleared when the tab/session ends; localStorage persists ✓
  • B. localStorage clears on tab close while sessionStorage persists
  • C. Both persist indefinitely across sessions
  • D. sessionStorage is shared across all open tabs
Correct answer: A. sessionStorage lives only for the tab's session, whereas localStorage persists until explicitly cleared.
How does an element with `position: sticky` behave?
  • A. Acts relative until a scroll threshold, then sticks like fixed within its container ✓
  • B. Is always fixed relative to the viewport
  • C. Is removed from flow like absolute positioning
  • D. Behaves identically to static positioning
Correct answer: A. A sticky element scrolls normally until it hits its offset, then it stays pinned within its container.
What is the difference between the `async` and `defer` attributes on a <script>?
  • A. defer runs after parsing in document order; async runs as soon as it loads, order not guaranteed ✓
  • B. async waits for full parse while defer runs immediately
  • C. Both block HTML parsing while downloading
  • D. defer always runs before the script tag is reached
Correct answer: A. Deferred scripts execute in order after parsing; async scripts execute whenever they finish loading.
The same-origin policy and CORS restrictions are enforced by which component?
  • A. The browser, based on the server's response headers ✓
  • B. The server rejecting all cross-origin traffic
  • C. The DNS resolver during lookup
  • D. The operating system firewall
Correct answer: A. CORS is a browser-enforced mechanism that reads server headers to decide whether to expose responses.
Which flexbox property aligns a single line of items along the cross axis?
  • A. justify-content
  • B. align-items ✓
  • C. place-items
  • D. order
Correct answer: B. `align-items` positions items along the cross axis, while `justify-content` handles the main axis.
Which change forces a layout reflow rather than only a repaint?
  • A. Changing an element's `color`
  • B. Changing an element's `width` ✓
  • C. Changing `background-color`
  • D. Changing `outline-color`
Correct answer: B. Altering geometry like `width` triggers reflow, whereas color changes only repaint.
In a flex container, which property aligns items along the main axis?
  • A. align-items
  • B. justify-content ✓
  • C. align-content
  • D. flex-wrap
Correct answer: B. justify-content distributes flex items along the main axis; align-items works on the cross axis.
What does console.log(typeof null) output?
  • A. "null"
  • B. "undefined"
  • C. "object" ✓
  • D. "boolean"
Correct answer: C. typeof null returns "object", a long-standing quirk of JavaScript.
Which React hook is designed to run side effects after a component renders?
  • A. useState
  • B. useEffect ✓
  • C. useMemo
  • D. useRef
Correct answer: B. useEffect runs side effects such as data fetching or subscriptions after render.
Event delegation on the DOM primarily relies on which mechanism?
  • A. Event capturing only
  • B. Inline event handlers
  • C. Event bubbling ✓
  • D. Calling event.preventDefault
Correct answer: C. Delegation attaches one listener to a parent and relies on events bubbling up from children.
Given const arr = [1,2,3], what does arr.map(x => x*2) produce?
  • A. The original array mutated in place
  • B. undefined
  • C. A new array [2,4,6] ✓
  • D. The number 6
Correct answer: C. map returns a new array with the callback applied to each element, leaving the original untouched.
What is the purpose of a CSS media query?
  • A. To import external stylesheets
  • B. To apply styles conditionally based on device or viewport characteristics ✓
  • C. To query the DOM for elements
  • D. To define animation keyframes
Correct answer: B. Media queries apply rules only when conditions like viewport width or orientation are met.
What does Promise.all([p1, p2]) resolve to when both promises succeed?
  • A. The first promise to resolve
  • B. An array of all resolved values, rejecting if any promise rejects ✓
  • C. The last promise to resolve
  • D. undefined
Correct answer: B. Promise.all resolves with an array of results, but rejects immediately if any input rejects.
Which display value makes an element a flex container while keeping it inline-level?
  • A. flex
  • B. grid
  • C. inline-flex ✓
  • D. inline-block
Correct answer: C. inline-flex creates a flex container that participates in inline flow rather than as a block.
What is the key difference between == and === in JavaScript?
  • A. == compares references while === compares values
  • B. == performs type coercion while === does not ✓
  • C. They behave identically
  • D. === performs type coercion while == does not
Correct answer: B. == coerces operands to a common type before comparing; === requires the same type and value.
Why should a stable key prop be provided when rendering a list in React?
  • A. To style each list item uniquely
  • B. To help React identify which items changed, were added, or removed for efficient reconciliation ✓
  • C. To sort the list automatically
  • D. To stop the list from ever re-rendering
Correct answer: B. Keys let React match elements between renders so it can update the DOM minimally and correctly.

Hard round 30 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.
In what order do synchronous code, a `Promise.then` callback, and a `setTimeout(fn, 0)` callback execute?
  • A. synchronous, setTimeout, then
  • B. synchronous, then, setTimeout ✓
  • C. then, synchronous, setTimeout
  • D. setTimeout, then, synchronous
Correct answer: B. Sync code runs first, then the microtask queue (Promise) drains before the macrotask (setTimeout).
Which of the following creates a new CSS stacking context?
  • A. Setting `position: relative` with no z-index
  • B. Setting `opacity` to a value less than 1 ✓
  • C. Setting `display: block`
  • D. Setting `margin: auto`
Correct answer: B. An `opacity` below 1 establishes a new stacking context, unlike `position: relative` alone.
What does the Temporal Dead Zone (TDZ) describe?
  • A. The span where a let/const binding exists but cannot be accessed before its declaration ✓
  • B. The time before a `var` is hoisted
  • C. The gap between two event-loop ticks
  • D. The delay before a Promise resolves
Correct answer: A. The TDZ is the region from block start until a let/const declaration, where accessing it throws.
What causes 'layout thrashing' in the browser?
  • A. Interleaving DOM reads (e.g. offsetHeight) with writes, forcing repeated synchronous reflows ✓
  • B. Declaring too many CSS classes
  • C. Loading many large images
  • D. Attaching many passive event listeners
Correct answer: A. Reading layout properties after writes repeatedly invalidates and recomputes layout, thrashing performance.
Inside a regular (non-arrow) function invoked as a plain function call in non-strict mode, what is `this`?
  • A. undefined
  • B. The global object (window) ✓
  • C. The function object itself
  • D. The nearest enclosing object
Correct answer: B. In non-strict mode a plain function call sets `this` to the global object; strict mode makes it undefined.
In the CSS cascade, which declaration wins over the others?
  • A. A plain inline style attribute
  • B. A stylesheet rule marked `!important` ✓
  • C. An ID selector in the stylesheet
  • D. A user-agent default rule
Correct answer: B. An `!important` declaration overrides normal declarations, including a plain inline style.
Why does batching visual updates inside `requestAnimationFrame` improve rendering performance?
  • A. It aligns DOM updates with the browser's paint cycle, avoiding wasted intermediate layout work ✓
  • B. It moves the work onto a Web Worker thread
  • C. It permanently caches the computed layout
  • D. It disables reflow for the element
Correct answer: A. rAF schedules work right before paint, so multiple updates coalesce into one frame instead of many reflows.
When you access `obj.toString()` and `obj` has no own `toString`, how does JavaScript resolve it?
  • A. It walks the prototype chain until it finds the property or reaches null ✓
  • B. It checks only the object's own properties
  • C. It searches the global scope
  • D. It inspects the constructor's arguments
Correct answer: A. Property lookup traverses the prototype chain via [[Prototype]] until the property or null is reached.
Which of these is render-blocking by default and delays the first paint?
  • A. A stylesheet loaded via <link> in the <head> ✓
  • B. An image referenced inside CSS
  • C. A script with the `async` attribute
  • D. A font declared with `rel="preload"`
Correct answer: A. External CSS in the head is render-blocking because the browser needs the CSSOM before painting.
What is a common cause of memory leaks in long-running single-page apps?
  • A. Detached DOM nodes still referenced by JavaScript closures ✓
  • B. Using `const` instead of `let`
  • C. Running many CSS keyframe animations
  • D. Receiving large JSON responses
Correct answer: A. DOM nodes removed from the tree but still referenced by JS cannot be garbage collected, leaking memory.
What does the CSS property will-change: transform primarily do?
  • A. Immediately animates the transform
  • B. Hints the browser to promote the element onto its own compositor layer for optimization ✓
  • C. Disables all transforms on the element
  • D. Forces an immediate synchronous reflow
Correct answer: B. will-change tells the browser to prepare optimizations, typically by promoting the element to a compositor layer.
In the browser event loop, how are microtasks (e.g. Promise callbacks) scheduled relative to macrotasks (e.g. setTimeout)?
  • A. Macrotasks always run before microtasks
  • B. The microtask queue is fully drained after each macrotask, before the next macrotask runs ✓
  • C. They alternate strictly one-to-one
  • D. Microtasks run only after every macrotask is exhausted
Correct answer: B. After each macrotask the engine drains the entire microtask queue before picking up the next macrotask.
What most directly causes 'layout thrashing'?
  • A. Using too many CSS classes
  • B. Loading large images
  • C. Repeatedly interleaving DOM reads (like offsetHeight) and writes, forcing multiple synchronous reflows ✓
  • D. Using inline styles instead of stylesheets
Correct answer: C. Reading a layout property after a write forces a synchronous reflow; doing this in a loop causes thrashing.
What does a JavaScript closure capture from its enclosing scope?
  • A. A copy of each variable's value at creation time
  • B. A reference to the variable binding, so later mutations are visible ✓
  • C. Only primitive values, never objects
  • D. Nothing; closures do not retain outer variables
Correct answer: B. Closures hold a live reference to the variable binding, so changes made after creation are observable.
What is the effect of the defer attribute on a <script> tag?
  • A. Executes the script immediately, blocking HTML parsing
  • B. Downloads in parallel and executes after HTML parsing completes, preserving document order ✓
  • C. Downloads and executes as soon as available, out of order
  • D. Prevents the script from loading at all
Correct answer: B. defer lets the script download without blocking parsing and runs it in order after the document is parsed.
Which selector has the highest CSS specificity?
  • A. #id ✓
  • B. two chained classes (.a.b)
  • C. three type selectors (div p span)
  • D. the :hover pseudo-class
Correct answer: A. An id selector scores (1,0,0), outranking any combination of class or type selectors.
What problem does React's useCallback hook solve?
  • A. It caches an expensive computed value
  • B. It returns a memoized function reference that stays stable across renders to avoid needless child re-renders ✓
  • C. It replaces useEffect for side effects
  • D. It stores and updates component state
Correct answer: B. useCallback memoizes a function identity so referential-equality-sensitive children do not re-render unnecessarily.
What best describes a CSS 'stacking context'?
  • A. The order in which stylesheets are loaded
  • B. A z-axis ordering context, created by properties such as position with z-index or opacity below 1 ✓
  • C. The cascade order determined by specificity
  • D. The source order of elements in the HTML
Correct answer: B. A stacking context governs how descendants are painted along the z-axis and is formed by triggers like z-index or opacity < 1.
Why can for...in be problematic when iterating over an array?
  • A. It is always slower than for...of
  • B. It iterates enumerable property keys including inherited ones and yields string indices, not just elements ✓
  • C. It cannot access array element values
  • D. It only ever visits the first element
Correct answer: B. for...in walks enumerable keys (including inherited ones) as strings, which is unsuited to ordered array element iteration.
What does the CSS containment value contain: layout enable?
  • A. Wrapping of overflowing text
  • B. Isolation of the element's internal layout so internal changes don't affect the outside document layout ✓
  • C. Automatic centering of the element
  • D. Blocking the element from being styled
Correct answer: B. contain: layout isolates layout so recalculations inside the element don't trigger reflow of the rest of the page.

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: August 2026.