Frontend interview questions

92 questions, easy to hard. Read one, then answer it out loud: an AI interviewer follows up, hints when you're stuck and grades your answer.

Frontend interviews range across the whole browser: semantic HTML and accessibility, CSS layout, JavaScript, TypeScript, React, performance and testing.

HTML and Accessibility

  1. A page is built entirely from div elements: the header, navigation, main content, article and even the buttons. Explain what semantic HTML is, which elements you'd use instead, and who benefits.

  2. A login form uses grey placeholder text inside each box instead of labels, and shows errors only by turning the box red. Explain what's wrong for users, especially those using screen readers, and how you'd fix the form.

  3. A news site's images all have alt text that just says image, and the logo inside the home link has none. Explain how you'd write alternative text for a news photo, a decorative divider and the logo link.

  4. A dropdown menu opens when you click a styled div, and keyboard users can't reach or open it at all. The design team has also removed all focus outlines. Explain how you'd make it work with a keyboard.

  5. A colleague has added ARIA roles to almost every element on a page and asks if that makes it accessible. Explain what ARIA is for, the first rule of using it, and good examples of when it is needed.

  6. A design uses pale grey text on white, marks required fields only in red, and has a large animated background. Explain the accessibility problems and how you'd fix each one.

  7. Your team wants to know whether its app is accessible before an audit. Explain how you'd test it, combining automated tools with manual checks, and what each catches.

  8. You're building a confirmation dialog that appears over the page. Keyboard users currently tab behind it, and screen reader users don't know it opened. Explain how you'd make the dialog accessible from opening to closing.

CSS and Layout

  1. A card is set to be three hundred pixels wide, but with padding and a border it takes up more than that and breaks the layout. Explain the CSS box model, why this happens, and how you'd fix it.

  2. You add a class to make a button red, but it stays blue, and a colleague suggests adding important. Explain how the browser decides which CSS rule wins, and a better fix.

  3. You need to build a navigation bar with a logo on the left and links on the right, and a photo gallery with rows of equal-sized tiles. Explain the difference between flexbox and grid, and which you'd use for each.

  4. A designer asks you to centre a loading spinner in the middle of a full-height panel, centre a line of text, and centre a fixed-width page column. Explain the techniques you'd use for each and why centring has a reputation for being hard.

  5. A desktop-only site needs to work on phones. Explain how you'd make the layout responsive, including the viewport setting, breakpoints and units.

  6. A dropdown menu is hidden behind the next section, even with a z-index of nine thousand nine hundred and ninety-nine. A sticky header also stops sticking. Explain how CSS positioning and stacking contexts work and how you'd fix both.

  7. A user who sets a larger default font size in their browser finds your site's text doesn't grow. Explain the differences between pixels, rems, ems and viewport units, and which you'd use for text, spacing and layout.

  8. A large app has one global stylesheet with thousands of rules. Changing a style for one page breaks others, and nobody dares delete anything. Explain how you'd organise the CSS so it scales with the team.

Fundamentals

  1. A teammate asks why the style guide says to use const by default, let when a value changes, and never var. Explain the differences between the three, and what goes wrong in a for loop that uses var to create click handlers that each log their own loop number.

  2. A form check compares the user's input to zero with double equals, and it passes when the input is an empty string. Explain why, how double equals and triple equals differ, and how you'd compare values safely, including objects and the value NaN.

  3. A function sets a default page size by writing the argument or twenty, but when a caller passes zero the page size becomes twenty anyway. Explain which values JavaScript treats as falsy, why this bug happens, and how you'd fix it.

  4. A junior developer asks why JavaScript has both null and undefined, and which one they should use for a user's middle name when it isn't known. Explain where each comes from, how they compare, and how you'd check for either safely.

  5. A function receives a settings object, changes one of its fields, and suddenly settings elsewhere in the app have changed too. But when the same function changes a number it was passed, nothing outside changes. Explain why, and how you'd avoid the surprise.

  6. You're reviewing code that reads five fields from an options object one line at a time, and builds a new array by looping over two others and pushing each item. Explain how destructuring and the spread and rest syntax would make this shorter, and what to watch out for.

  7. You have an array of orders, each with a status and a total. You need the totals of the paid orders, and then their sum. Explain how you'd do this with map, filter and reduce instead of a for loop, and when a plain loop might still be better.

  8. You need a function called makeCounter. Each call to it returns a new counter function, and each time you call a counter it returns the next number, starting at one. Two counters must count independently, and nothing outside should be able to change a counter's number. Explain how you'd build it and why it works.

  9. A class has a method that reads this dot name. Calling it directly works, but passing the method to a button's click handler or to a timer makes this undefined. Explain how JavaScript decides what this means, and give two ways to fix the bug.

  10. You copy a user object with the spread syntax before editing their address, but the original user's address changes too. Explain why, and compare the ways you could make a full copy, including their limits.

  11. A checkout adds ten pence and twenty pence and the test expecting thirty pence fails, because the result is a tiny bit more than point three. Explain why JavaScript numbers behave like this, and how you'd handle money safely.

Objects and Prototypes

  1. You're building a settings screen where the field to update arrives as a name in a variable, and some settings objects are missing whole sections. Explain the ways to read and change an object's properties, and how to read nested values without crashing.

  2. You have an object mapping product names to stock counts and you need to list every product with its count, and the total stock. Explain the ways to loop over an object, and which you'd choose.

  3. Someone coming from Java asks how classes work in JavaScript. Explain how you'd write a bank account class with an owner, a balance and a deposit method, and then a savings account that adds interest.

  4. You create an array and call its map method, but when you log the array's own properties, map isn't there. Explain where map comes from, how JavaScript looks up properties through the prototype chain, and how classes relate to this.

  5. A shopping cart class exposes its items array, and other code keeps pushing to it directly, skipping the cart's validation. Explain how you'd protect the cart's data, using private fields, getters and setters.

  6. You're tracking which users are online, counting visits per page, and attaching extra data to DOM elements without leaking memory. Explain when you'd use a plain object, a Map, a Set or a WeakMap for each, and why.

  7. A state update in your app changes a nested field on an existing object, and the screen doesn't refresh. A colleague suggests Object.freeze. Explain what immutability means here, what freeze does and doesn't do, and how you'd update nested data without mutation.

  8. A game has a class hierarchy: Character, then Flying Character and Swimming Character, and now designers want a duck that both flies and swims. Explain why the inheritance tree struggles with this, and how you'd redesign it using composition.

DOM and Events

  1. Without any framework, you need to find a page's error message box, put a message in it, and make it visible. Explain how you'd select the element, change its text and styles, and why you'd be careful about using innerHTML.

  2. You need a button that counts how many times it has been clicked, without a framework. Explain how you'd attach the click handler, what the event object gives you, and how you'd remove the handler later.

  3. A to-do list adds a click listener to every delete button. New items added later don't respond, and with thousands of items the page is sluggish. Explain event bubbling, and how event delegation solves both problems.

  4. A sign-up form posts its data with JavaScript, but every time you press the button the whole page reloads and the request is lost. Explain why, and how you'd handle the submission properly, including pressing Enter and showing validation errors.

  5. A script in the page's head can't find the elements it needs, and the page also appears blank for a moment while it downloads. Explain how script tags block the HTML parser, and how the defer and async attributes and module scripts change that.

  6. Your app needs to remember a user's theme choice, keep an unsent message draft per tab, and save thousands of offline records. Explain the browser's storage options, which fits each case, and what should never be stored there.

  7. A comments section builds its HTML by joining strings that include each comment's text, then sets it with innerHTML. A user posts a comment containing a script that steals other visitors' data. Explain how the attack works and how you'd defend against it.

  8. A feed should load more posts as the user nears the bottom. The current version listens to every scroll event, sometimes loads the same page twice, and gets slower the longer you scroll. Explain how you'd rebuild it.

Asynchronous JavaScript

  1. A page loads a user, then that user's orders, then the first order's details. Each step needs the result of the one before. Explain how you'd write this with nested callbacks, with promises, and with async and await, and why the later styles are easier to read and to handle errors in.

  2. A function loads a user and checks if they are an admin, but every user is treated as an admin, and logging the result shows a pending promise. Explain what went wrong, and how you'd find bugs like this sooner.

  3. A page fetches data with async and await, and when the network fails the page just stays on a loading spinner while the console shows an unhandled promise rejection. Explain how errors travel through promises, and how you'd handle them so the user sees a helpful message.

  4. A script does four things in this order: it logs A; it schedules a timeout with zero delay that logs B; it creates an already-resolved promise whose then callback logs C; and it logs D. Say in what order the letters are printed, and explain why using the call stack, the task queue and the microtask queue.

  5. An app calls fetch to load a profile. When the server returns a four hundred and four or a five hundred page, the app doesn't show an error: instead it crashes later trying to read the JSON. Explain how fetch reports errors, and how you'd write a safe wrapper.

  6. A search box fetches results as the user types. Sometimes the results shown don't match the text in the box, because an older, slower request finished after a newer one. Explain why this happens and how you'd fix it.

  7. A resize handler recalculates a chart hundreds of times while the user drags the window. Explain how you'd write a debounce function that only runs the work once the user has stopped for a quarter of a second, and how it differs from throttling.

  8. A dashboard loads ten independent widgets. The current code awaits each request one after another, so the page takes the sum of all ten response times. Explain how you'd load them in parallel, what should happen when one request fails or hangs, and how you'd avoid overwhelming the server if there were a thousand requests instead of ten.

  9. A payment status request sometimes fails because the server is briefly overloaded. Explain how you'd write a helper that retries failed requests, which failures it should retry, how long to wait between attempts, and how to avoid making the overload worse.

TypeScript

  1. A colleague says that since the project moved to TypeScript, the app can't crash with a type error any more. Explain what TypeScript actually checks, when it checks it, and what it can't protect you from.

  2. A code review flags a function whose parameter is typed as any. Explain what any does, why unknown is usually the better choice for a value you don't know yet, and what the never type means.

  3. An app draws circles, which have a radius, and rectangles, which have a width and a height. Explain how you'd type a shape so that a function computing the area can only read the fields that exist for each kind, and so the compiler warns you if someone adds a triangle and forgets to handle it.

  4. A new teammate adds type annotations to every single variable, even ones assigned a number literal, and asks whether that's best practice. Explain how TypeScript infers types, where annotations add value, and where they're just noise.

  5. With strict mode turned on, the compiler complains that a user's address might be undefined when you read the city. A colleague silences it with an exclamation mark. Explain what the compiler is warning about, and better ways to handle it.

  6. A code review asks why some object shapes in the project are interfaces and others are type aliases. Explain the differences, what each can do that the other can't, and what convention you'd suggest.

  7. You want a function that returns the first item of an array. Called with an array of numbers it should return a number, and with an array of users it should return a user, with no casting. Then you want a second function that reads a property from an object by name, where the compiler rejects property names that don't exist. Explain how you'd type both.

  8. You have a User type with an id, a name, an email, a password hash and a creation date. You need three related types: the fields a user may change in an update, where every field is optional and the id can't be changed; the public profile, with only the id and name; and the input for creating a user, with everything except the id and the creation date. Explain how you'd define them without copying fields by hand.

  9. A function accepts either a string, a list of strings or an error object, and needs to handle each differently. Explain how TypeScript narrows a union type inside your checks, and how you'd write your own reusable type guard.

  10. A config object lists the allowed user roles, but functions accept any string as a role, and somewhere the list is accidentally modified. Explain how readonly types and the as const assertion would help, and how you'd derive the role type from the list.

  11. Your app fetches a list of products from a third-party API. The current code parses the JSON and casts it to an array of products. One day the API starts returning prices as strings, and the app shows wrong totals without any error. Explain why the types didn't catch this, and how you'd make the boundary safe so bad data is caught where it enters the app.

  12. Your team has a large JavaScript codebase and wants to move to TypeScript without stopping feature work. Explain how you'd plan the migration, which compiler settings you'd start with, and how you'd tighten them over time.

React

  1. You're explaining React to someone who knows HTML and JavaScript but has never used it. They ask: what is a component, and what is JSX? Walk them through how you'd build a greeting card that shows a person's name, and how you'd reuse it for three different people.

  2. A like button shows a heart and a count of likes. Clicking it adds one to the count. The button's label text is chosen by the page that uses it. Explain which of these values should be props and which should be state, and what happens on screen when the button is clicked.

  3. You have an array of to-do items, each with an ID and some text, and you need to show them as a list. Explain how you'd render it in React, why React warns about a missing key prop, and what could go wrong if you used each item's position in the array as its key.

  4. A page has two sibling components: a search box and a results list. Each keeps its own copy of the search text in state, so typing in the box doesn't update the list. Explain how you would restructure the components so the list always shows results for what's typed in the box.

  5. You're building a sign-up form in React with a name field and a newsletter checkbox, and the submit button should only be enabled once the name isn't empty. Explain how you'd wire the inputs to state, and what a controlled input is.

  6. A shopping cart component should show a loading message, an error, an empty-cart message, or the list of items. A colleague's version sometimes shows a stray zero on the page. Explain how you'd render each case, and where the zero comes from.

  7. A component shows a counter that should go up by one every second. It keeps the count in state, and an effect with an empty dependency list starts an interval that sets the count to the current count plus one. On screen, the counter goes from zero to one and then stays at one. Explain why, and how you'd fix it.

  8. A component stores a list of items and a filter, and uses an effect to copy the filtered list into a third piece of state whenever either changes. The screen flickers with stale results for a moment. Explain what's wrong and how you'd simplify it.

  9. A profile page fetches a user in an effect whenever the user ID prop changes. When you click quickly between profiles, sometimes the wrong user's data appears. Explain why, how you'd fix it, and when you'd reach for a data-fetching library instead.

  10. The current user and theme are passed as props through six layers of components that don't use them, just to reach a few deep ones. Explain how React context would help, how you'd set it up, and the costs of using it.

  11. Three components each track the window's width with their own state, effect and resize listener, copied and pasted. Explain how you'd extract a custom hook for this, and what rules hooks must follow.

  12. A page has a filter text box above a list of ten thousand products. The parent component holds the filter text in state, filters the products on every render, and renders every matching row. Typing in the box feels laggy: each keystroke takes hundreds of milliseconds. Explain how you would find the cause and make typing feel instant.

Browser and Performance

  1. An interviewer asks what happens between typing a web address into the browser and seeing the page. Explain the main steps, from the network to drawing the page on screen.

  2. Your manager says search rankings depend on Core Web Vitals and asks what they are. Explain the three metrics, what good scores look like, and what typically hurts each.

  3. A marketing page takes eight seconds to show anything on a mid-range phone. Explain how you'd find out why, and the changes most likely to make it fast.

  4. A product page shows a five megabyte hero photo to every visitor, and the gallery below makes the text jump as images load. Explain how you'd optimise the images.

  5. HTTP Caching
    • medium
    • Pro

    After every deploy some users see a broken page, because their browser mixes the new HTML with old cached JavaScript. Explain how HTTP caching headers work, and how you'd set them for HTML and for static assets.

  6. Your front end on one domain calls your API on another, and the browser blocks the response with a CORS error, although the same request works from a terminal. Explain what's happening and how to fix it properly.

  7. A sidebar slides in by animating its left position, and on phones the animation stutters. Explain why, and how you'd make it smooth at sixty frames per second.

  8. Users report that your single-page app gets slower the longer it stays open, and the tab eventually crashes. Explain how you'd confirm a memory leak, find its cause, and the usual culprits in front-end code.

Testing

  1. Your team is starting to write tests for a web app and argues about whether to write unit tests, integration tests or end-to-end tests. Explain the difference between them and how you'd balance them.

  2. You need tests for a function that formats an amount of pence as a price in pounds. Explain how you'd structure a good unit test, which cases you'd cover, and how you'd name the tests.

  3. A component's tests check its internal state values and break every time it's refactored, even when nothing changes for users. Explain how you'd test a login form component the way a user uses it.

  4. A component loads data from an API. Its tests call the real API, so they are slow and fail whenever the API is down. Explain how you'd mock the network, and the risks of mocking too much.

  5. A test passes on your machine but fails one run in ten in continuous integration. Explain how you'd investigate it and the most common causes of flaky front-end tests.

  6. Your codebase has hundreds of snapshot tests, and developers update them all with one command whenever they fail without reading the changes. Explain what snapshot tests are good and bad at, and how you'd fix this habit.

  7. You're adding end-to-end tests for checkout using a browser automation tool such as Playwright. Explain how you'd write them so they catch real problems without being slow and brittle.

  8. You join a team with a large front end that has no tests, frequent regressions and a deadline-driven culture. Explain how you'd introduce testing in a way the team will keep up.

Questions about practising

How should I prepare for frontend interview questions?
Practise answering them out loud, not just reading them. Explaining an answer under follow-up questions is what interviews test. Work through the 92 questions here from easy to hard, and revisit the ones you struggle with.
Can I practise frontend interview questions with an AI?
Yes. Open any question and start a voice session: an AI interviewer asks it, follows up on your answer, gives hints when you're stuck and grades your answer with written feedback when the call ends.
Are these frontend interview questions free?
5 of the 92 questions are free to practise. Sign in with Google, no card needed. Pro unlocks the rest, plus practice calls to your phone.