Skip to content
Resume Studioby M2Toolkit

24 role-specific questions

Frontend Developer Interview Questions & Answers

Frontend interviews test whether you can build fast, accessible interfaces that work in every browser — and whether you understand what happens underneath your framework. Expect questions on JavaScript fundamentals, CSS layout, accessibility and web performance, plus your framework of choice.

Free, no sign-up. 110 questions in this role's practice pool, including behavioural, HR and situational questions.

HTML, CSS & the browser interview questions

Semantics, accessibility, CSS layout, web performance and how browsers render — the fundamentals behind every front-end role.

  1. 1.

    Why does semantic HTML matter? Give examples.

    BeginnerTechnical

    What the interviewer is evaluating

    Accessibility and quality awareness, not just visual output.

    Key points a strong answer covers

    • Meaningful elements. Use elements for their meaning: <nav>, <main>, <button>, <article>.
    • Accessibility. Assistive technology relies on semantics for landmarks, roles and keyboard behaviour.
    • SEO / machines. Search engines and other tools understand the structure better.
    • div button problem. A clickable <div> isn't focusable or keyboard operable; <button> is, for free.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Using headings for font size rather than structure.
    • Building buttons from divs.

    Likely follow-up questions

    • What does a <button> give you that a <div onClick> doesn't?
    • How should heading levels be structured on a page?
    Example strong answer

    Semantic HTML means using elements for what they are, not how they look: <header>, <nav>, <main>, <article>, <button>, a single logical heading outline. It matters mostly for accessibility: screen-reader users jump between landmarks and headings, and a real <button> is focusable, announced as a button and works with Enter and Space automatically — a <div onClick> gives you none of that. It also helps search engines understand the page and makes the code easier to read. Accessibility audits I've done usually find most problems come from non-semantic markup, so fixing that first is cheap and effective.

    Practise this question and get feedback
  2. 2.

    How do you make a web application accessible?

    IntermediateTechnical

    What the interviewer is evaluating

    Practical accessibility knowledge beyond buzzwords.

    Key points a strong answer covers

    • Semantics first. Native elements and proper labels before ARIA.
    • Keyboard. Everything usable by keyboard with a visible focus; manage focus in dialogs.
    • Contrast / text. Sufficient contrast, alt text, text that resizes.
    • ARIA used carefully. ARIA only when there's no native equivalent; live regions for updates.
    • Testing. Test with axe/Lighthouse and a real screen reader; follow WCAG 2.2 AA.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Adding ARIA to everything instead of using native elements.
    • Relying only on automated tools.

    Likely follow-up questions

    • How would you build an accessible modal dialog?
    • What can automated tools not catch?
    Example strong answer

    I start with semantics: native elements, labelled form fields and a sensible heading structure — that solves most issues. Then keyboard: every action reachable by Tab, a visible focus style, and focus managed properly in modals and menus — moved in on open, trapped, returned on close. Colour contrast of at least 4.5:1 for body text, meaningful alt text, and layouts that survive 200% zoom. ARIA only where there's no native option — aria-live for toast messages, aria-expanded on a disclosure. I test with axe in CI, then manually with the keyboard and VoiceOver or NVDA, because automated tools catch maybe a third of issues. WCAG 2.2 AA is the usual target.

    Practise this question and get feedback
  3. 3.

    Explain the CSS box model and box-sizing: border-box.

    BeginnerTechnical

    What the interviewer is evaluating

    Whether you understand how element sizes are calculated — the root of many layout bugs.

    Key points a strong answer covers

    • Four layers. Every box is content, padding, border and margin.
    • content-box default. By default width applies to the content, so padding and border make it wider.
    • border-box. border-box makes width include padding and border — easier to reason about.
    • Margin collapse. Vertical margins between blocks can collapse.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Not knowing why an element with width: 100% and padding overflows.
    • Forgetting margin collapsing.

    Likely follow-up questions

    • When do vertical margins collapse?
    • How does box-sizing affect a flex item's size?
    Example strong answer

    Every element is a box made of content, then padding, then border, then margin outside. With the default box-sizing: content-box, width sets only the content, so a width: 100% element with 20px padding ends up wider than its parent and overflows. With border-box, width includes padding and border, so the element is exactly the width you set — that's why most resets apply *, *::before, *::after { box-sizing: border-box }. Margins sit outside the border and don't count, and adjacent vertical margins between blocks can collapse into one, which surprises people.

    Practise this question and get feedback
  4. 4.

    When would you use Flexbox and when CSS Grid?

    BeginnerTechnical

    What the interviewer is evaluating

    Whether you choose the layout tool that fits the problem rather than forcing one everywhere.

    Key points a strong answer covers

    • Flexbox one dimension. Flexbox lays items out along one axis.
    • Grid two dimensions. Grid controls rows and columns together.
    • Content vs layout first. Flex is content-driven; Grid defines the layout and places content into it.
    • Examples. Flex for toolbars and nav bars; Grid for page layouts, galleries, card grids.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Using Grid or Flex dogmatically for everything.
    • Not knowing gap works in Flexbox too.

    Likely follow-up questions

    • How would you build a responsive card grid without media queries?
    • How do you centre an element both ways?
    Example strong answer

    Flexbox is for one dimension — a row or a column — and it's content-driven: items size themselves and you distribute space, which is perfect for a nav bar, a toolbar, or aligning an icon with text. Grid is two-dimensional: you define rows and columns and place items into them, so it suits page layouts, dashboards and card galleries — grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)) gives a responsive card grid without media queries. They combine well: a Grid page layout with Flexbox inside each card. Both support gap, and centring is just display: grid; place-items: center.

    Practise this question and get feedback
  5. 5.

    What happens between typing a URL and seeing the page? Focus on how the browser renders it.

    IntermediateTechnical

    What the interviewer is evaluating

    End-to-end understanding of loading and rendering.

    Key points a strong answer covers

    • Network. DNS lookup, connection (TCP/TLS), HTTP request, response.
    • Parse HTML / DOM. The browser parses HTML into the DOM.
    • CSSOM / render blocking. CSS builds the CSSOM; CSS and synchronous scripts block rendering.
    • Layout and paint. DOM + CSSOM → render tree → layout → paint → composite.
    • Scripts. Use defer/async so scripts don't block parsing.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Skipping the network part entirely.
    • Not mentioning what blocks rendering.

    Likely follow-up questions

    • What's the difference between async and defer?
    • What causes a layout (reflow), and why is it expensive?
    Example strong answer

    First the network: a DNS lookup, then a TCP and TLS connection, then the HTTP request — often served by a CDN. As the HTML streams in, the browser parses it into the DOM and discovers other resources. CSS is render-blocking: the browser builds the CSSOM before it paints. A plain <script> blocks parsing too, which is why I use defer or modules. The DOM and CSSOM combine into a render tree; layout calculates each box's position and size; paint fills pixels; and compositing assembles layers on the GPU. To speed it up: small critical CSS, deferred scripts, preloading the LCP image and fonts, and avoiding layout-triggering work after load.

    Practise this question and get feedback
  6. 6.

    What are Core Web Vitals, and how would you improve each one?

    IntermediateTechnical

    What the interviewer is evaluating

    Measurable performance knowledge.

    Key points a strong answer covers

    • LCP. LCP measures loading — when the largest content element appears (good ≤ 2.5s).
    • INP. INP measures responsiveness to interactions (good ≤ 200ms). It replaced FID.
    • CLS. CLS measures visual stability (good ≤ 0.1).
    • Fixes. LCP: optimise and preload the hero; INP: break up long tasks; CLS: reserve space for media and ads.
    • Field data. Measure with field data (CrUX, RUM), not only Lighthouse.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Still citing FID as the responsiveness metric.
    • Only quoting Lighthouse lab scores.

    Likely follow-up questions

    • What's the difference between lab and field data?
    • What usually causes a poor INP?
    Example strong answer

    Core Web Vitals are Google's user-centred metrics. LCP, Largest Contentful Paint, measures loading — good is 2.5 seconds or less; I improve it by serving a compressed, correctly sized hero image, preloading it, using a CDN and removing render-blocking resources. INP, Interaction to Next Paint, replaced FID and measures responsiveness — good is 200 ms or less; it's usually hurt by long JavaScript tasks, so I split work up, defer non-essential scripts and reduce hydration cost. CLS measures layout shift — good is 0.1 or less; I reserve space for images, ads and embeds and avoid font swaps that shift text. I track field data from real users, not just Lighthouse.

    Practise this question and get feedback
  7. 7.

    What is CORS, and why do you get CORS errors?

    IntermediateTechnical

    What the interviewer is evaluating

    Understanding of the same-origin policy and where to fix CORS issues.

    Key points a strong answer covers

    • Same-origin policy. Browsers block reading responses from a different origin by default.
    • Server opts in. The server opts in with Access-Control-Allow-Origin and related headers.
    • Preflight. Non-simple requests trigger an OPTIONS preflight first.
    • Fix on the server. It's fixed on the server (or via a proxy), not in front-end code.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Trying to fix CORS in the frontend fetch call.
    • Setting Access-Control-Allow-Origin: * with credentials.

    Likely follow-up questions

    • Why doesn't Postman show CORS errors?
    • What changes when the request includes cookies?
    Example strong answer

    CORS is a relaxation of the browser's same-origin policy. By default a page on app.example.com can send a request to api.other.com, but the browser won't let the JavaScript read the response unless the server says it's allowed, with headers like Access-Control-Allow-Origin. For non-simple requests — say a PUT, or a JSON content type, or a custom header — the browser first sends an OPTIONS preflight to ask permission. So a CORS error is fixed on the server: allow the specific origin, methods and headers, or route through a same-origin proxy. Tools like Postman don't enforce it because it's a browser rule. With cookies you need credentials: 'include' and a specific origin, not *.

    Practise this question and get feedback
  8. 8.

    Compare cookies, localStorage, sessionStorage and IndexedDB.

    BeginnerTechnical

    What the interviewer is evaluating

    Choosing client storage safely.

    Key points a strong answer covers

    • Cookies sent to server. Cookies go with every request to their domain; httpOnly cookies are invisible to JavaScript.
    • localStorage persists. localStorage persists, is synchronous, string-only, ~5MB per origin.
    • sessionStorage per tab. sessionStorage is cleared when the tab closes.
    • IndexedDB. IndexedDB is async and stores large structured data and blobs.
    • Security. Don't keep auth tokens where XSS can read them; prefer httpOnly cookies.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Storing JWTs in localStorage without considering XSS.
    • Storing large data in cookies.

    Likely follow-up questions

    • Why is localStorage a poor place for an auth token?
    • When would you reach for IndexedDB?
    Example strong answer

    Cookies are small and sent automatically with every request to their domain, which makes them the right place for a session — as httpOnly, Secure and SameSite, JavaScript can't read them, which protects against token theft through XSS. localStorage persists across sessions, is synchronous and string-only with roughly 5 MB per origin — fine for preferences like the theme, but any script on the page can read it, so not for tokens. sessionStorage is the same but per tab and cleared when it closes — handy for a form draft. IndexedDB is asynchronous and stores large structured data and files, which is what offline apps and editors use.

    Practise this question and get feedback
  9. 9.

    How do you protect a front-end application against XSS and CSRF?

    AdvancedTechnical

    What the interviewer is evaluating

    Security awareness for the client side.

    Key points a strong answer covers

    • XSS = injected script. XSS is untrusted content executing as script in your page.
    • Escape / avoid raw HTML. Frameworks escape by default; avoid raw HTML or sanitise it (DOMPurify).
    • CSP. A Content Security Policy limits which scripts can run.
    • CSRF. CSRF tricks a logged-in browser into sending a request.
    • CSRF defences. SameSite cookies, CSRF tokens and checking the Origin header.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Thinking React makes XSS impossible.
    • Confusing CSRF with XSS.

    Likely follow-up questions

    • How can XSS still happen in a React app?
    • Why do SameSite cookies help against CSRF?
    Example strong answer

    XSS is when untrusted content runs as script in your page — a comment containing <script> or an onerror attribute. React and other frameworks escape text by default, so the risks are the escape hatches: dangerouslySetInnerHTML, innerHTML, and javascript: URLs in links. I avoid raw HTML, and when I must render it — rich text from a CMS — I sanitise it with DOMPurify. A Content Security Policy is a second layer that blocks inline and unknown scripts. CSRF is different: another site makes the user's browser send a request with their cookies. SameSite=Lax or Strict cookies block most of it, and for sensitive actions I add CSRF tokens or check the Origin header.

    Practise this question and get feedback
  10. 10.

    How do you build a responsive layout?

    BeginnerTechnical

    What the interviewer is evaluating

    Practical mobile-first CSS.

    Key points a strong answer covers

    • Mobile first. Start with the small-screen layout and add breakpoints with min-width.
    • Fluid units. Use fluid units, clamp() and fr instead of fixed pixels.
    • Flexible layout. Grid and Flexbox that wrap naturally.
    • Responsive media. Images with max-width: 100% and srcset/sizes.
    • Container queries / testing. Container queries for components; test on real devices.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Designing desktop first and patching mobile.
    • Fixed-width containers causing horizontal scroll.

    Likely follow-up questions

    • What do container queries solve that media queries don't?
    • Why use rem for font sizes?
    Example strong answer

    I work mobile first: base styles for small screens, then min-width breakpoints where the content needs them rather than for specific devices. Layouts use Grid and Flexbox that wrap on their own — repeat(auto-fill, minmax(…)) handles a lot without breakpoints — with fluid units like %, fr and rem, and clamp() for typography that scales smoothly. Images get max-width: 100% and srcset with sizes so phones download smaller files. For components that appear in different widths, like a card in a sidebar or main column, container queries are better than viewport media queries. I check for horizontal scrolling and test on real phones, not just DevTools.

    Practise this question and get feedback

JavaScript interview questions

Closures, the event loop, async code, scope and the prototype chain — the core of every front-end and Node.js interview.

  1. 1.

    Explain closures in JavaScript, with a practical example.

    BeginnerTechnical

    What the interviewer is evaluating

    Whether you understand lexical scope and can connect it to real code, not just recite a definition.

    Key points a strong answer covers

    • Function + outer scope. A closure is a function bundled with references to the variables of the scope it was created in.
    • Variables stay alive. The captured variables live on after the outer function returns.
    • Practical use. Private state, factories, memoisation, debounce/throttle and event handlers all rely on closures.
    • Pitfall. Watch for stale values (e.g. in React effects), var in loops, and accidentally retaining large objects.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Saying a closure is “a function inside a function” without explaining what it captures.
    • No example — interviewers want to see you've used one.

    Likely follow-up questions

    • What does for (var i = 0; i < 3; i++) setTimeout(() => console.log(i)) print, and why?
    • How can a closure cause a memory leak?
    Example strong answer

    A closure is a function together with the variables from the scope where it was defined. Because the function keeps a reference to that scope, those variables stay alive even after the outer function has returned. A simple example is a counter factory: makeCounter() declares let count = 0 and returns a function that increments it — each counter has its own private count. I use closures every day for event handlers, debounce helpers and module-private state. The main pitfall is stale values: a React effect or a timer can capture an old variable, so you need the right dependencies or a ref.

    Practise this question and get feedback
  2. 2.

    What is the event loop, and how do microtasks differ from macrotasks?

    IntermediateTechnical

    What the interviewer is evaluating

    Whether you can predict the order async code runs in, which matters for debugging race conditions and UI jank.

    Key points a strong answer covers

    • Single thread + call stack. JavaScript runs one call stack on a single thread; the event loop decides what runs next.
    • Task queue. Timers, I/O and UI events queue (macro)tasks.
    • Microtasks first. After each task, all queued microtasks (promise callbacks, await continuations) run before the next task.
    • Rendering / blocking. Long synchronous work or endless microtasks block rendering.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Saying setTimeout(fn, 0) runs immediately.
    • Forgetting that microtasks drain completely before the browser can paint.

    Likely follow-up questions

    • In what order do console.log, setTimeout and Promise.resolve().then log?
    • How would you break up a long-running loop so the page stays responsive?
    Example strong answer

    JavaScript runs on one thread with one call stack. The event loop takes the next task — a timer callback, an I/O completion or a UI event — and runs it to completion. After every task it drains the microtask queue, which holds promise reactions and await continuations, and only then can the browser render and pick the next task. So console.log('a'); setTimeout(() => log('b')); Promise.resolve().then(() => log('c')); log('d') prints a, d, c, b. In practice that's why a heavy synchronous loop freezes the UI; I split long work into chunks with setTimeout or scheduler.yield, or move it to a Web Worker.

    Practise this question and get feedback
  3. 3.

    What's the difference between var, let and const?

    BeginnerTechnical

    What the interviewer is evaluating

    Basic language fluency: scope, hoisting and immutability of bindings.

    Key points a strong answer covers

    • Function vs block scope. var is function-scoped; let and const are block-scoped.
    • Hoisting / TDZ. All are hoisted, but var is initialised to undefined while let/const sit in the temporal dead zone until declared.
    • const binding, not value. const stops reassignment, not mutation — a const object can still change.
    • Re-declaration. var allows re-declaration in the same scope; let/const don't.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Claiming const makes objects immutable.
    • Saying let and const aren't hoisted at all.

    Likely follow-up questions

    • How would you make an object truly read-only?
    • Why does var in a for-loop cause bugs with callbacks?
    Example strong answer

    var is function-scoped, can be re-declared, and is hoisted and initialised to undefined, so you can read it before the declaration line. let and const are block-scoped; they're hoisted too, but they're in the temporal dead zone until the declaration runs, so early access throws. const prevents reassigning the binding, not changing the value — const user = {} can still get new properties; for a read-only object you'd use Object.freeze, which is shallow. In modern code I default to const, use let when a value really changes, and avoid var.

    Practise this question and get feedback
  4. 4.

    Explain promises and async/await. How do you handle errors and run requests in parallel?

    IntermediateTechnical

    What the interviewer is evaluating

    Practical async skills: error handling, sequencing and concurrency.

    Key points a strong answer covers

    • Promise states. A promise is pending, then fulfilled or rejected, once.
    • async/await is syntax over promises. An async function returns a promise; await pauses that function until the promise settles.
    • Error handling. Use try/catch around awaits (or .catch), and never leave a rejection unhandled.
    • Parallel vs sequential. Awaiting in a loop is sequential; Promise.all runs them together; allSettled waits for every result.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Awaiting independent requests one by one, making the page slower.
    • Using Promise.all without considering that one rejection fails the whole batch.

    Likely follow-up questions

    • When would you choose Promise.allSettled over Promise.all?
    • How would you limit concurrency to five requests at a time?
    Example strong answer

    A promise represents a value that will arrive later; it's pending, then fulfilled or rejected exactly once. async/await is syntax over promises: an async function always returns a promise, and await pauses just that function until the promise settles, so code reads top to bottom. For errors I wrap awaits in try/catch, or attach .catch when I'm not awaiting. If requests don't depend on each other I start them together with Promise.all, which rejects as soon as one fails; when I need every outcome — say, uploading ten files and reporting which failed — I use Promise.allSettled. For large batches I limit concurrency with a small pool.

    Practise this question and get feedback
  5. 5.

    How is the value of this determined in JavaScript?

    IntermediateTechnical

    What the interviewer is evaluating

    Whether you understand call-site binding — a frequent source of bugs in callbacks and classes.

    Key points a strong answer covers

    • Depends on the call. this is set by how a function is called, not where it's written.
    • Method / default binding. obj.fn() sets this to obj; a plain call gives undefined in strict mode (the global object otherwise).
    • Explicit binding. call, apply and bind set this explicitly.
    • Arrow functions. Arrow functions don't have their own this; they use the enclosing scope's.
    • new. With new, this is the newly created object.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Saying this refers to the function itself.
    • Not knowing why a method loses this when passed as a callback.

    Likely follow-up questions

    • Why does setTimeout(obj.method, 100) lose this, and how do you fix it?
    • When would you avoid an arrow function as an object method?
    Example strong answer

    this is decided by the call, not the definition. Called as a method — user.greet() — this is user. Called as a plain function, it's undefined in strict mode or the global object otherwise. call, apply and bind set it explicitly, and with new it's the newly created instance. Arrow functions don't bind their own this; they take it from the surrounding scope, which is why they're handy in callbacks inside class methods. A classic bug is passing obj.method to setTimeout or an event listener: it's called without the object, so this is lost — fix it with obj.method.bind(obj) or an arrow wrapper.

    Practise this question and get feedback
  6. 6.

    Explain prototypal inheritance. How do ES6 classes relate to it?

    IntermediateTechnical

    What the interviewer is evaluating

    Depth of language knowledge beyond syntax.

    Key points a strong answer covers

    • Prototype chain. Objects link to a prototype; property lookups walk up the chain until found or null.
    • Shared methods. Methods on the prototype are shared by all instances rather than copied.
    • Classes are syntax. class is mostly syntax over constructor functions and prototypes.
    • Creating links. Object.create, constructor functions and extends set up the prototype link.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Describing JavaScript classes as if they copy methods like Java classes.
    • Confusing prototype (on functions) with an object's internal prototype.

    Likely follow-up questions

    • What's the difference between Foo.prototype and Object.getPrototypeOf(foo)?
    • How does hasOwnProperty differ from the in operator?
    Example strong answer

    Every object has an internal link to another object, its prototype. When you read a property that isn't on the object itself, JavaScript looks it up on the prototype, then that object's prototype, and so on until it reaches null. That's how inheritance works: methods live once on a prototype and every instance shares them. ES6 classes are largely syntax over this — class Admin extends User sets Admin.prototype's prototype to User.prototype, and methods in the class body go on the prototype. You can also link objects directly with Object.create(proto). Knowing this helps when debugging instanceof or checking own properties with Object.hasOwn.

    Practise this question and get feedback
  7. 7.

    What is event delegation, and why is it useful?

    BeginnerTechnical

    What the interviewer is evaluating

    DOM fundamentals and awareness of performance with many elements.

    Key points a strong answer covers

    • Bubbling. Most events bubble from the target up through its ancestors.
    • One listener on a parent. Attach one listener to a common parent instead of one per child.
    • Identify the target. Use event.target.closest(selector) to find which child was clicked.
    • Benefits. Works for elements added later and uses fewer listeners.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Using event.target directly when the click lands on a nested icon inside the button.
    • Forgetting events like focus don't bubble (use focusin).

    Likely follow-up questions

    • What's the difference between event.target and event.currentTarget?
    • How do stopPropagation and preventDefault differ?
    Example strong answer

    Events bubble: a click on a list item also fires on the list and every ancestor. Event delegation uses that by putting one listener on a parent — say the <ul> of a long to-do list — and working out which child was clicked with event.target.closest('li'). It means fewer listeners and it automatically handles items added later, which is ideal for tables or infinite lists. Two things to watch: use closest because the target might be an icon inside the button, and some events such as focus don't bubble, so you'd use focusin instead.

    Practise this question and get feedback
  8. 8.

    What's the difference between == and ===? What about Object.is?

    BeginnerTechnical

    What the interviewer is evaluating

    Precision about type coercion.

    Key points a strong answer covers

    • Coercion. == converts types before comparing; === doesn't.
    • Strict equality. === requires the same type and value.
    • Edge cases. null == undefined is true; NaN === NaN is false; objects compare by reference.
    • Object.is. Object.is is like === but treats NaN as equal to itself and +0/-0 as different.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Saying == compares values and === compares references.
    • Not mentioning that objects are compared by reference with both.

    Likely follow-up questions

    • Why is [] == false true?
    • How would you compare two objects by their contents?
    Example strong answer

    === is strict equality: same type and same value, no conversion. == applies type coercion first, which produces surprises like '0' == false and [] == false both being true. The one coercion I find genuinely useful is x == null, which catches both null and undefined. Objects and arrays are compared by reference with either operator, so two identical-looking objects aren't equal. Object.is is like === except Object.is(NaN, NaN) is true and Object.is(0, -0) is false. In code I use === by default and lint against ==.

    Practise this question and get feedback
  9. 9.

    What's the difference between debounce and throttle? When would you use each?

    IntermediateTechnical

    What the interviewer is evaluating

    Practical performance techniques for event-heavy UIs.

    Key points a strong answer covers

    • Debounce waits for a pause. Debounce runs once after events stop for a set time.
    • Throttle limits rate. Throttle runs at most once per interval while events keep firing.
    • Use cases. Debounce: search-as-you-type, autosave. Throttle: scroll, resize, mousemove.
    • Implementation. Both are built with timers (and a closure holding the timer id).

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Mixing up which is which.
    • Debouncing scroll position tracking so it only updates after the user stops.

    Likely follow-up questions

    • How would you implement debounce in a few lines?
    • What does a leading-edge debounce do?
    Example strong answer

    Both limit how often a function runs during a burst of events. Debounce waits until the events stop for, say, 300 ms and then runs once — ideal for search-as-you-type so you send one request when the user pauses, or for autosave. Throttle runs at most once per interval while the events keep coming — good for scroll or resize handlers that need regular updates. Debounce is a closure holding a timer: each call clears the previous timeout and sets a new one. Throttle tracks the last run time or uses a timer flag. Where available, requestAnimationFrame is often the best throttle for visual updates.

    Practise this question and get feedback
  10. 10.

    How do you copy an object in JavaScript? What's the difference between a shallow and a deep copy?

    IntermediateTechnical

    What the interviewer is evaluating

    Understanding of references and immutable update patterns.

    Key points a strong answer covers

    • Shallow copy. Spread and Object.assign copy only the top level; nested objects are still shared.
    • Deep copy. A deep copy duplicates nested objects too; structuredClone does this natively.
    • JSON trick limits. JSON.parse(JSON.stringify(x)) loses dates, functions, undefined, Maps and cycles.
    • Why it matters. Accidental shared references cause state bugs, especially in React/Redux.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Thinking spread makes a full independent copy.
    • Recommending the JSON trick without its limitations.

    Likely follow-up questions

    • What can't structuredClone copy?
    • How would you update a nested property immutably?
    Example strong answer

    Assigning an object just copies the reference. Spread ({...obj}) and Object.assign make a shallow copy: the top-level properties are new, but nested objects are still shared, so changing copy.address.city changes the original. For a deep copy I use structuredClone, which handles nested objects, arrays, Dates, Maps and even cycles — but not functions or DOM nodes. The old JSON.parse(JSON.stringify()) trick loses dates, undefined and functions. In React state I usually don't deep copy at all; I copy just the path I'm changing, like {...user, address: {...user.address, city}}.

    Practise this question and get feedback
  11. 11.

    Compare ES modules and CommonJS.

    IntermediateTechnical

    What the interviewer is evaluating

    Familiarity with tooling and how code is loaded in browsers and Node.

    Key points a strong answer covers

    • Syntax. ESM uses import/export; CommonJS uses require and module.exports.
    • Static vs dynamic. ESM imports are static, enabling tree shaking; require is a runtime call.
    • Loading. ESM loads asynchronously and supports top-level await; CommonJS loads synchronously.
    • Interop. Node chooses via "type": "module" or .mjs/.cjs; interop has rough edges.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Not knowing why tree shaking needs static imports.
    • Ignoring that exports in ESM are live bindings.

    Likely follow-up questions

    • What is a dynamic import() used for?
    • Why might a library ship both ESM and CommonJS builds?
    Example strong answer

    ES modules use import and export; CommonJS uses require and module.exports. ESM imports are static — they're resolved before the code runs — so bundlers can tree-shake unused exports, and the browser supports ESM natively. require is an ordinary synchronous function call at runtime, which is flexible but harder to analyse. ESM loads asynchronously, supports top-level await and exports live bindings. In Node, the package's "type" field or the .mjs/.cjs extension decides which system a file uses. For code splitting I use dynamic import(), which returns a promise.

    Practise this question and get feedback
  12. 12.

    How do memory leaks happen in a JavaScript application, and how would you find one?

    AdvancedTechnical

    What the interviewer is evaluating

    Debugging maturity on long-lived single-page apps.

    Key points a strong answer covers

    • Garbage collection basics. Memory is freed when objects become unreachable; leaks are unwanted references.
    • Common causes. Forgotten listeners, intervals, subscriptions, growing caches, globals and detached DOM nodes.
    • Tools. Compare heap snapshots in DevTools and look at retainers.
    • Fixes. Clean up in teardown (effects' cleanup), use AbortController, WeakMap for caches.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Saying JavaScript can't leak because it's garbage collected.
    • No method — guessing instead of measuring.

    Likely follow-up questions

    • What's a detached DOM node?
    • How does AbortController help clean up listeners?
    Example strong answer

    JavaScript is garbage collected, so a leak is really an unwanted reference that keeps objects reachable. Common causes in SPAs are event listeners or intervals that are never removed when a component unmounts, subscriptions that aren't cancelled, caches that only grow, and detached DOM nodes still referenced from JS. To find one I reproduce the action several times — open and close a modal ten times — take heap snapshots before and after in Chrome DevTools, and compare what's growing, then follow the retainers to the code holding it. Fixes are cleanup functions in effects, AbortController signals for listeners and fetches, and WeakMap for object-keyed caches.

    Practise this question and get feedback
  13. 13.

    When would you use map, filter, reduce and forEach?

    BeginnerTechnical

    What the interviewer is evaluating

    Idiomatic, readable code and understanding of immutability.

    Key points a strong answer covers

    • map transforms. map returns a new array of the same length with each item transformed.
    • filter selects. filter returns a new array with the items that pass a test.
    • reduce accumulates. reduce combines items into one value — a total, an object, a group-by.
    • forEach for side effects. forEach is for side effects and returns undefined; it can't be chained or broken out of.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Using map just to loop (and ignoring the returned array).
    • Writing unreadable reduce calls when map + filter is clearer.

    Likely follow-up questions

    • How would you group an array of orders by customer?
    • Which of these mutate the original array?
    Example strong answer

    map transforms every item and returns a new array of the same length — turning API records into view models, for example. filter returns the items that pass a test, like active users. reduce folds the array into one value: a sum, a lookup object, or grouping orders by customer. forEach is for side effects such as logging; it returns undefined and you can't break out of it. None of them mutate the original array, which suits React state. I prefer a readable filter then map over a clever reduce, and for very large data I'd use a single loop.

    Practise this question and get feedback
  14. 14.

    Does fetch reject on a 404 or 500 response? How do you handle HTTP errors properly?

    IntermediateTechnical

    What the interviewer is evaluating

    Real-world API handling and robustness.

    Key points a strong answer covers

    • Only network errors reject. fetch only rejects on network failures; HTTP errors still resolve.
    • Check response.ok. Check response.ok or the status code and throw yourself.
    • Timeouts / aborts. Use AbortController (or AbortSignal.timeout) for timeouts and cancellation.
    • User-facing handling. Parse the error body, show a useful message, and retry only safe requests.

    Suggested answer structure

    1. Define it in one sentence.
    2. Explain how it works underneath.
    3. Give a practical example from code or a project.
    4. Close with a trade-off, pitfall or when you'd use it.

    Common mistakes

    • Assuming a try/catch around fetch catches 500 errors.
    • Never cancelling requests when a component unmounts.

    Likely follow-up questions

    • How would you add a 10-second timeout?
    • Which requests is it safe to retry automatically?
    Example strong answer

    No — fetch only rejects for network-level failures such as DNS errors or the connection dropping. A 404 or 500 resolves normally, so I always check response.ok (or the status) and throw an error with the status and the parsed error body. I wrap that in a small API helper so every call handles it the same way. For timeouts and cancellation I pass an AbortController signal — AbortSignal.timeout(10000) for a deadline, and aborting on unmount so stale responses don't update the UI. I'd only auto-retry idempotent requests like GETs, with backoff.

    Practise this question and get feedback

Behavioural & HR questions you'll also get

These come up in almost every frontend developer interview. Story questions are best answered with STAR — Situation, Task, Action, Result.

  • Tell me about yourself.

    BeginnerHR

    What the interviewer is evaluating

    Whether you can give a concise, relevant pitch that frames your experience around this job.

    Key points a strong answer covers

    • Present. Start with your current role and what you do.
    • Relevant past. Pick the most relevant past experience.
    • Strength / achievement. Include one strength or achievement with evidence.
    • Why this role. Finish with why this role is the next step.

    Suggested answer structure

    1. Present — your current role in one or two sentences.
    2. Past — the experience most relevant to this job.
    3. Proof — one achievement or strength with evidence.
    4. Future — why this role is the logical next step.

    Common mistakes

    • Reciting your whole CV chronologically.
    • Personal life story unrelated to the job.
    • Going over two minutes.

    Likely follow-up questions

    • Why are you looking to leave your current role?
    • What would your manager say is your biggest strength?
    Example strong answer

    I'm a front-end developer with four years' experience, currently at a fintech start-up where I build the customer dashboard in React and TypeScript. Before that I spent two years at an agency building e-commerce sites, which taught me to work fast with lots of different clients. The thing I'm proudest of recently is leading our move to a shared component library, which cut the time to build new screens by about a third. I'm now looking for a role where I can work on a larger product with a strong design system, which is exactly what drew me to this position.

  • Why should we hire you?

    BeginnerHR

    What the interviewer is evaluating

    Whether you understand the role and can match your strengths to its needs with evidence.

    Key points a strong answer covers

    • Role's needs. Show you understand what the role needs.
    • Matching strengths. Match two or three strengths to those needs.
    • Evidence. Back each with evidence.
    • Enthusiasm. Close with genuine enthusiasm.

    Suggested answer structure

    1. Name the two or three things the role needs most.
    2. Match each with your experience and evidence.
    3. Add what makes you different.
    4. Finish with genuine interest.

    Common mistakes

    • Generic claims like 'I'm hardworking' with no evidence.
    • Comparing yourself to other candidates you don't know.

    Likely follow-up questions

    • What would you do in your first 90 days?
    • What's one area where you'd need support?
    Example strong answer

    From the job description and our conversation, you need someone who can take ownership of the customer onboarding process, work with sales and product, and improve the numbers. I've done exactly that for three years: at my current company I redesigned onboarding for new accounts and cut the time to first value from 14 days to 6. I'm comfortable working across teams — I run a weekly session with sales and product on customer feedback — and I'm very data-driven, so I'd measure everything from day one. I'm also genuinely excited about your product, because it solves a problem I've seen customers struggle with.

  • Tell me about a time you disagreed with a teammate. How did you handle it?

    BeginnerBehavioural

    What the interviewer is evaluating

    Handling conflict constructively and keeping relationships.

    Key points a strong answer covers

    • Listened to their view. Show you listened to understand their view.
    • Used facts / common goal. Bring it back to facts or a shared goal.
    • Resolution & relationship. Resolve it and keep the relationship.

    Suggested answer structure

    1. Situation — one or two sentences of context.
    2. Task — what you were responsible for.
    3. Action — what you did, step by step (say “I”).
    4. Result — what changed, with a number if you can back it up.
    5. Reflection — what you learned or would do differently.

    Common mistakes

    • Making the other person the villain.
    • A story where you were simply right and they gave in.

    Likely follow-up questions

    • What if you couldn't reach agreement?
    • Have you ever been wrong in a disagreement?
    Example strong answer (a fictional story — use your own)

    On a website rebuild, a senior designer wanted an animated, image-heavy homepage, and I was worried it would hurt mobile load times and SEO. As the developer responsible for performance, I needed us to agree before the sprint started. I asked her to walk me through what she was trying to achieve — she wanted the brand to feel premium. I built two quick prototypes, one with her full design and one with lighter animations, and we tested both on a mid-range phone together. Hers took nearly six seconds to load. We agreed on a version that kept the key animation but lazy-loaded the rest. The page launched loading in under two seconds, and she later asked me to review designs earlier. I learned that testing together beats debating.

  • Tell me about a mistake you made and what you learned.

    BeginnerBehavioural

    What the interviewer is evaluating

    Honesty, accountability and learning.

    Key points a strong answer covers

    • Real mistake owned. Own a real mistake.
    • Fixed it. Show how you fixed it and who you told.
    • Changed behaviour. Show what you changed afterwards.

    Suggested answer structure

    1. Situation — one or two sentences of context.
    2. Task — what you were responsible for.
    3. Action — what you did, step by step (say “I”).
    4. Result — what changed, with a number if you can back it up.
    5. Reflection — what you learned or would do differently.

    Common mistakes

    • Choosing a fake mistake like 'I work too hard'.
    • Blaming others.

    Likely follow-up questions

    • How did your manager react?
    • How do you know you haven't repeated it?
    Example strong answer (a fictional story — use your own)

    In my first year as a marketing coordinator, I sent a promotional email to our whole list with the wrong discount code — I'd tested the email but not clicked the code itself. Within an hour customers were complaining that it didn't work. I told my manager immediately, set the wrong code to apply the discount too, and sent a short correction email with an apology. We lost very little revenue, and some customers replied thanking us for the quick fix. Since then I use a pre-send checklist that includes testing every link and code as a customer would, and I asked for a second person to check any campaign to more than 10,000 people.

  • Describe a situation where you worked under pressure or to a tight deadline.

    BeginnerBehavioural

    What the interviewer is evaluating

    Prioritisation, composure and delivery.

    Key points a strong answer covers

    • The pressure. Make the pressure concrete.
    • Prioritised. Show how you prioritised.
    • Communicated. Show how you kept people informed.
    • Delivered. Show the outcome.

    Suggested answer structure

    1. Situation — one or two sentences of context.
    2. Task — what you were responsible for.
    3. Action — what you did, step by step (say “I”).
    4. Result — what changed, with a number if you can back it up.
    5. Reflection — what you learned or would do differently.

    Common mistakes

    • Glorifying working all night as the solution.
    • No mention of prioritising.

    Likely follow-up questions

    • What would you do if it was clear you couldn't make the deadline?
    • How do you stop pressure affecting quality?
    Example strong answer (a fictional story — use your own)

    Two days before a client presentation, our analyst fell ill and I had to finish the market research report she'd been leading. I listed everything left and asked the account director which sections the client cared about most — pricing and competitor comparison. I focused on those, reused verified data from our previous report, and moved the appendix to a follow-up email. I sent a short update each evening so nobody was surprised. We delivered the core report on time, the client approved the next phase, and the appendix followed two days later. I learned to ask early what matters most rather than trying to do everything equally well.

  • What would you do if you realised you were going to miss a deadline?

    BeginnerSituational

    What the interviewer is evaluating

    Transparency and problem solving.

    Key points a strong answer covers

    • Tell people early. Flag it as soon as you know.
    • Assess the gap. Work out how far off you are.
    • Options. Offer options: reduced scope, help, a new date.
    • Prevent repeats. Learn why it happened.

    Suggested answer structure

    1. Clarify the situation and what's at stake.
    2. Say what you'd do first, and why.
    3. Explain who you'd involve and how you'd communicate.
    4. Describe how you'd check the outcome and prevent a repeat.

    Common mistakes

    • Waiting until the deadline to say anything.
    • Promising you'll just work all night.

    Likely follow-up questions

    • What if your manager is unavailable?
    • Has this happened to you?
    Example strong answer

    I'd tell the person depending on it as soon as I realised, not at the deadline. Before that conversation I'd work out how far off I am and why, so I could offer options: delivering the most important part on time and the rest a few days later, getting help from a colleague, or agreeing a new date. Then I'd let them decide what works best for them, and keep them updated. Afterwards I'd look at why it slipped — usually underestimating something — so I plan better next time.

Ready to answer them out loud?

Run a timed frontend developer mock interview, type or speak your answers, and get a score breakdown with what to improve.

Interview questions for related roles