HireHireInterview Quizzes › Web Developer

Web Developer Interview Questions

Think you're ready? These are the questions that actually decide Web 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 Web Developer quiz — get your score →

The Web 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 HTML, which element is the semantically correct choice for the main navigation links of a website?
  • A. <div class="nav">
  • B. <nav> ✓
  • C. <section>
  • D. <aside>
Correct answer: B. The <nav> element is the semantic HTML5 element specifically intended for major navigation blocks.
What is the difference between `==` and `===` in JavaScript?
  • A. `==` compares values with type coercion, `===` compares value and type without coercion ✓
  • B. `===` compares value with type coercion, `==` is stricter
  • C. They are identical in behaviour
  • D. `==` only works on numbers, `===` only on strings
Correct answer: A. `==` performs type coercion before comparing, while `===` (strict equality) requires both value and type to match.
In CSS, an element has `position: absolute`. Relative to what is it positioned?
  • A. The viewport, always
  • B. Its nearest positioned (non-static) ancestor ✓
  • C. Its immediate parent regardless of the parent's position
  • D. The <body> element only
Correct answer: B. An absolutely positioned element is positioned relative to its nearest ancestor that has a position other than static, falling back to the initial containing block.
Which CSS Flexbox property controls how items are distributed along the main axis?
  • A. align-items
  • B. justify-content ✓
  • C. flex-wrap
  • D. align-content
Correct answer: B. justify-content aligns and distributes flex items along the main axis, whereas align-items works on the cross axis.
A page makes an AJAX request to a different domain and the browser blocks it. Which mechanism must the server implement to allow it?
  • A. HTTPS redirection
  • B. CORS (Cross-Origin Resource Sharing) headers ✓
  • C. Gzip compression
  • D. A service worker
Correct answer: B. The server must send appropriate CORS headers (like Access-Control-Allow-Origin) to permit cross-origin requests under the same-origin policy.
What does the JavaScript keyword `let` provide that `var` does not?
  • A. Function-level scope
  • B. Block-level scope ✓
  • C. Global scope by default
  • D. Automatic type checking
Correct answer: B. `let` is block-scoped (confined to the nearest enclosing block), while `var` is function-scoped.
Which HTTP status code indicates that a requested resource was not found on the server?
  • A. 200
  • B. 301
  • C. 404 ✓
  • D. 500
Correct answer: C. 404 Not Found means the server could not find the requested resource.
In the CSS box model, which property adds space between an element's border and its content?
  • A. margin
  • B. padding ✓
  • C. border-spacing
  • D. outline
Correct answer: B. Padding is the space between the content and the border; margin is the space outside the border.
What will `console.log(typeof null)` output in JavaScript?
  • A. "null"
  • B. "object" ✓
  • C. "undefined"
  • D. "number"
Correct answer: B. Due to a long-standing behaviour in JavaScript, typeof null returns the string "object".
Which method is used to select a single element by its unique ID in vanilla JavaScript?
  • A. document.querySelectorAll('#id')
  • B. document.getElementsByClassName('id')
  • C. document.getElementById('id') ✓
  • D. document.getElementsByTagName('id')
Correct answer: C. document.getElementById returns the single element whose id matches the given string.

Medium round 10 questions

In CSS, an element has `padding: 20px` and `box-sizing: border-box` with `width: 200px`. What is the total rendered content-box width (ignoring borders)?
  • A. 240px
  • B. 200px
  • C. 160px ✓
  • D. 180px
Correct answer: C. With border-box, the declared 200px includes padding, so content width = 200 - 20 - 20 = 160px.
You want a click handler on a parent `<ul>` to respond to clicks on any of its `<li>` children, including ones added later. Which approach is best?
  • A. Attach a separate listener to each `<li>` on page load
  • B. Use event delegation: one listener on the `<ul>` and check `event.target` ✓
  • C. Poll the DOM every second and rebind listeners
  • D. Use inline `onclick` attributes on each `<li>`
Correct answer: B. Event delegation puts one listener on the parent and inspects event.target, so dynamically added children are handled automatically.
What does the CSS `gap` property control in a flex or grid container?
  • A. The outer margin around the entire container
  • B. The spacing between items (rows/columns) inside the container ✓
  • C. The padding inside each individual item
  • D. The border width of the container
Correct answer: B. `gap` sets the spacing between rows and columns of items within a flex or grid container.
Which HTTP status code should an API return when a request is understood but the client lacks permission to access the resource?
  • A. 401 Unauthorized
  • B. 403 Forbidden ✓
  • C. 404 Not Found
  • D. 500 Internal Server Error
Correct answer: B. 403 means the server understood the request but refuses to authorize it, whereas 401 specifically signals missing/invalid authentication.
In JavaScript, what will `console.log(0.1 + 0.2 === 0.3)` output and why?
  • A. `true`, because arithmetic is exact
  • B. `false`, due to floating-point representation error ✓
  • C. `true`, because JS rounds automatically
  • D. It throws a TypeError
Correct answer: B. IEEE 754 floating-point can't represent 0.1 and 0.2 exactly, so their sum is slightly off from 0.3 and the comparison is false.
You need to make several independent API calls and proceed only after all of them finish. Which is the most appropriate tool?
  • A. `Promise.all()` with an array of the fetch promises ✓
  • B. A `for` loop with `await` inside it
  • C. `Promise.race()`
  • D. `setTimeout()` chained callbacks
Correct answer: A. `Promise.all()` runs the promises concurrently and resolves once all complete, unlike a sequential awaited loop or race which resolves on the first.
In Git, you committed to your local branch but want to combine your last 3 unpushed commits into one before pushing. Which command is designed for this?
  • A. `git merge --squash HEAD~3`
  • B. `git rebase -i HEAD~3` ✓
  • C. `git reset --hard HEAD~3`
  • D. `git cherry-pick HEAD~3`
Correct answer: B. Interactive rebase lets you squash/fixup the last N commits into one; `reset --hard` would discard the changes entirely.
Which CSS media feature is used to apply styles only when the viewport is at most 768px wide?
  • A. `@media (min-width: 768px)`
  • B. `@media (max-width: 768px)` ✓
  • C. `@media screen and (width: 768px)`
  • D. `@media (device-width: 768px)`
Correct answer: B. `max-width: 768px` matches viewports up to and including 768px, the standard mobile-first breakpoint pattern.
A user reports your fetch call fails in the browser console with a CORS error. Where must the fix generally be applied?
  • A. Add a `<meta>` CORS tag in the HTML head
  • B. Set the appropriate `Access-Control-Allow-Origin` header on the server response ✓
  • C. Wrap the fetch in a try/catch block
  • D. Change the request from GET to POST
Correct answer: B. CORS is enforced by the browser based on server-sent response headers, so the server must send an allowing `Access-Control-Allow-Origin` header.
In React, what is the primary purpose of the `key` prop when rendering a list with `.map()`?
  • A. To style each list item uniquely
  • B. To help React identify which items changed, added, or removed for efficient reconciliation ✓
  • C. To store the item's data in local state
  • D. To set a unique HTML `id` attribute on each element
Correct answer: B. Keys give elements stable identity so React can reconcile the list efficiently and avoid re-rendering or misplacing items.

Hard round 10 questions

What does this log, in order? console.log('A'); setTimeout(() => console.log('B'), 0); Promise.resolve().then(() => { console.log('C'); setTimeout(() => console.log('D'), 0); }); queueMicrotask(() => console.log('E')); console.log('F');
  • A. A F C E B D ✓
  • B. A F C E D B
  • C. A C E F B D
  • D. A F E C B D
Correct answer: A. Sync runs first (A,F), then the microtask queue drains fully (C then E, since C was queued before E), and only then macrotasks in FIFO order (B, then D which was queued during the first microtask).
A senior sees this render slow. The list has 5,000 rows and a colleague immediately wraps every row in React.memo and adds useMemo everywhere. What is the correct first objection? function Row({ item }) { return <li>{item.label}</li>; } function List({ items }) { return <ul>{items.map(i => <Row key={i.id} item={i} />)}</ul>; }
  • A. React.memo will not help because Row has no props
  • B. Without profiling you don't know memo is the bottleneck; rendering 5,000 DOM nodes at once likely needs virtualization, not memoization ✓
  • C. useMemo on the map result fixes it since map allocates a new array each render
  • D. memo is useless in React 18 because the compiler auto-memoizes
Correct answer: B. The red flag is optimizing before measuring; a 5,000-node list is a DOM/layout cost that memoization can't fix, and the Profiler would point to virtualization instead.
This effect logs a stale count. Why, and what is the minimal correct fix? function Counter() { const [count, setCount] = useState(0); useEffect(() => { const id = setInterval(() => console.log(count), 1000); return () => clearInterval(id); }, []); return <button onClick={() => setCount(count + 1)}>{count}</button>; }
  • A. The interval closure captured count=0 from the first render; use a ref (or functional read) so the interval reads the latest value ✓
  • B. setInterval is unreliable in React; switch to setTimeout recursion
  • C. Add count to the dependency array is the only acceptable fix and has no downside
  • D. State updates are async so count is always one behind; add a useLayoutEffect
Correct answer: A. The empty-dep effect runs once and its closure permanently captures count=0; reading through a ref (updated each render) or adding count to deps both fix it, but only the ref avoids tearing down the interval every tick.
A CORS request from https://app.example.com sends cookies via fetch(url, { credentials: 'include' }). The server responds with Access-Control-Allow-Origin: * and Access-Control-Allow-Credentials: true. What happens?
  • A. It works; * matches every origin including the credentialed one
  • B. The browser blocks it: with credentials, the ACAO header must echo the specific origin, not the wildcard * ✓
  • C. It works only if SameSite=None is also set on the cookie
  • D. The preflight succeeds but the cookie is silently stripped from the actual request
Correct answer: B. The Fetch spec forbids the wildcard when credentials are included; the server must reflect the exact origin (and the browser rejects the response otherwise).
Predict the output: const obj = { val: 42, regular() { return (function () { return this?.val; })(); }, arrow() { return (() => this.val)(); } }; console.log(obj.regular(), obj.arrow());
  • A. 42 42
  • B. undefined 42 ✓
  • C. 42 undefined
  • D. undefined undefined
Correct answer: B. The inner regular function is called plain so its `this` is undefined (strict) giving undefined via optional chaining, while the arrow captures the method's `this` (obj) yielding 42.
Why did React's Fiber architecture replace the old stack reconciler? Pick the most fundamental reason.
  • A. Fiber uses less memory by reusing a single tree
  • B. Reconciliation was synchronous and uninterruptible; Fiber makes work a linked list of units that can be paused, prioritized, and resumed so high-priority updates aren't blocked ✓
  • C. Fiber removed the virtual DOM entirely in favor of direct DOM diffing
  • D. Fiber enables server components by moving rendering to the server
Correct answer: B. The stack reconciler recursed synchronously and couldn't be interrupted; Fiber restructures work into resumable units enabling priority scheduling and time-slicing.
A form input feels janky while filtering a huge list on each keystroke. You want the input to stay responsive and the list to update at lower priority without debouncing. Which is the idiomatic React 18 tool, and what's the caveat?
  • A. useMemo on the filtered list — it will skip recomputation
  • B. useDeferredValue on the filter text — the list renders with a lagging value, but the underlying filtering work must still be cheap enough or you also need virtualization ✓
  • C. useCallback on the onChange handler to prevent re-renders
  • D. useLayoutEffect to batch the updates synchronously
Correct answer: B. useDeferredValue lets the input update urgently while the list re-renders from a deferred value at lower priority, but it only reprioritizes—it doesn't make an expensive render cheap.
Storing a JWT in localStorage vs an httpOnly SameSite=Strict cookie: which statement is the accurate trade-off?
  • A. localStorage is safe because JS on your own origin is trusted
  • B. httpOnly cookies are immune to CSRF so no other defense is needed
  • C. localStorage is readable by any XSS-injected script (token exfiltration), while an httpOnly cookie is not JS-readable but reintroduces CSRF risk that SameSite/anti-CSRF tokens must address ✓
  • D. Both are equivalent since HTTPS encrypts the token in transit
Correct answer: C. localStorage tokens are exposed to XSS; httpOnly cookies block that read but are auto-sent by the browser, so CSRF protections become necessary.
Passing a value through React Context, this consumer re-renders on every provider render even when `user` is unchanged. What's the root cause? <AuthContext.Provider value={{ user, login, logout }}>
  • A. Context always re-renders all consumers regardless of value
  • B. The value object literal is a new reference each render, so all consumers re-render; memoize it with useMemo ✓
  • C. useContext doesn't support object values
  • D. You must wrap consumers in React.memo — context bypasses memo, so it can't be fixed
Correct answer: B. Context compares the value by reference; a fresh object literal each render invalidates all consumers, so the provider value should be memoized (splitting stable vs volatile values also helps).
Two rapid searches: request A (for 're') is slow, request B (for 'react') is fast and arrives first. Without care the UI shows A's results last. Which is the robust fix for this out-of-order async race?
  • A. Add a loading spinner so the user waits
  • B. Debounce the input to 300ms — this guarantees ordering
  • C. Track the latest request (e.g. an AbortController to cancel A, or an ignore flag / request id) so stale responses are discarded ✓
  • D. Wrap both in Promise.all so they resolve together
Correct answer: C. Cancelling superseded requests or tagging responses with a request id and dropping any that aren't the latest prevents a slow earlier response from clobbering fresh data; debouncing reduces but doesn't eliminate the race.

Prep for another role

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