ESC

Type to search the knowledge base.

Interview questions

Top 50 Frontend Interview Questions (with answers)

Revision list of 50 frontend interview questions for frontend engineers, with concise answers and links to deeper Frontend Beauty guides. Composite list for practice—not a ranked survey.

Composite practice list based on common frontend interview themes and publicly discussed fundamentals. Ordering is editorial for learning, not a statistical “most asked” ranking from a single company.

How to use this list

  • Answer out loud in 60–90 seconds, then check the written answer.
  • Where a “Deeper guide” link appears, open it after you attempt the answer yourself.
  • Pair with DSA, machine coding, and playground drills.
  1. javascript

    1.What is the JavaScript event loop?

    A single JS agent has one call stack. Host APIs (timers, network, DOM) finish work and queue callbacks. The event loop runs a macrotask until the stack is empty, drains all microtasks, may render, then takes the next macrotask. Workers are separate agents with their own stacks.

    Deeper guide →

  2. react

    2.What is React’s core mental model?

    UI is a function of state. You describe trees of elements; React reconciles descriptions and updates the host tree (DOM or native). Prefer data → view over imperative DOM mutation.

    Deeper guide →

  3. html

    3.What is semantic HTML and why does it matter?

    Use elements that match meaning (nav, main, button, label) so browsers, assistive tech, and crawlers understand structure. CSS can fake appearance; it cannot replace missing semantics without extra ARIA and keyboard work.

    Deeper guide →

  4. css

    4.What is the CSS box model?

    Every box has content, padding, border, and margin. With content-box, width applies to content only; with border-box, width includes padding and border. Most layout systems set border-box globally.

    Deeper guide →

  5. javascript

    5.What is the difference between microtasks and macrotasks?

    Microtasks (promise reactions, queueMicrotask, await continuations, MutationObserver) run after the current stack and before the next macrotask or paint. Macrotasks include timers, many DOM events, and other host tasks. That is why Promise.then usually runs before setTimeout(0). Footgun: endless microtasks starve rendering.

    Deeper guide →

  6. react

    6.What is reconciliation in React?

    The process of comparing the previous tree to the next one to decide what to insert, update, or remove. Same type at a position updates; different type remounts. Keys give list items identity.

    Deeper guide →

  7. html

    7.When should you use a link versus a button?

    Links navigate with href (open in new tab, bookmarkable, crawlable). Buttons perform actions on the page. Do not fake either with divs unless you reimplement keyboard and accessibility fully.

    Deeper guide →

  8. css

    8.What is the difference between content-box and border-box?

    content-box: specified width/height size the content area; padding and border add outside. border-box: specified width/height include content, padding, and border—usually easier for column math and components.

  9. javascript

    9.What is a closure in JavaScript?

    A function bundled with its lexical environment—the outer bindings it can still reach. Closures capture bindings, not frozen snapshots of values. Footgun: a long-lived callback that closes over a large object keeps that object alive for GC.

    Deeper guide →

  10. react

    10.Why do list keys matter?

    Keys preserve identity across renders so state and DOM attach to the correct items. Index keys break when you reorder or insert—inputs and local state glitch. Prefer stable IDs from data.

    Deeper guide →

  11. html

    11.Why should a page have a single main landmark?

    main identifies primary content and should appear once. It enables skip links and AT landmark navigation. Header/nav/footer sit outside main.

  12. css

    12.When do you use Flexbox versus Grid?

    Flexbox is strong for one-dimensional distribution (rows or columns of components). Grid is strong for two-dimensional page/section layouts. Real UIs often combine both.

  13. javascript

    13.What is the difference between var, let, and const?

    var is function-scoped and hoisted as undefined. let and const are block-scoped and stay in the temporal dead zone until initialized. const cannot rebind the identifier (object contents can still mutate). Prefer const by default, let when reassignment is needed.

  14. react

    14.What is the difference between props and state?

    Props are inputs from the parent (read-only for the child). State is data the component owns and can update over time. Lift state to the closest common owner that needs to coordinate children.

  15. html

    15.How do you correctly label form controls?

    Associate a label via for/id or wrap the control. Placeholder is a hint, not a label. Unlabeled inputs fail accessibility and often fail Testing Library role queries.

  16. css

    16.What do flex-grow, flex-shrink, and flex-basis do?

    flex-basis is the initial main size before free space is distributed. flex-grow shares positive free space. flex-shrink reduces items when space is tight. Defaults matter—know flex: 1 shorthand implications.

  17. javascript

    17.What is the temporal dead zone?

    From the start of a block until a let/const binding is initialized, accessing it throws ReferenceError. That gap is the TDZ. It prevents using bindings before their declaration runs.

  18. react

    18.What is a controlled input in React?

    The input’s value is driven by React state via value + onChange. Uncontrolled inputs keep value in the DOM and use refs. Controlled forms make validation and programmatic resets easier.

  19. html

    19.What are the rules of thumb for img alt text?

    Informative images need meaningful alt. Decorative images use empty alt (alt=""). Do not stuff keywords. Provide width/height or CSS aspect-ratio to limit CLS.

  20. css

    20.What is the difference between align-items and justify-content in Flexbox?

    justify-content distributes along the main axis; align-items aligns on the cross axis. Direction depends on flex-direction. Interviewers often swap axis names—draw it.

  21. javascript

    21.How does this binding work in JavaScript?

    this is set by the call site: default (undefined in strict, global in sloppy), method call (receiver), call/apply/bind, or new. Arrow functions do not have their own this—they capture lexical this. Footgun: extracting a method loses its receiver unless you bind it.

  22. react

    22.How does useState’s functional update work?

    setState(prev => next) uses the latest queued state, avoiding stale closures when the next value depends on the previous one. Prefer it inside async handlers and effects that schedule updates.

  23. html

    23.What is the difference between section, article, and div?

    div is generic styling/hook with no semantics. section is a thematic grouping with a heading. article is self-contained content that could stand alone (post, card widget).

  24. css

    24.What is the fr unit in CSS Grid?

    fr represents a fraction of available free space in the grid container. repeat(3, 1fr) builds equal columns after accounting for gaps and fixed tracks.

  25. javascript

    25.What is the difference between call, apply, and bind?

    call and apply invoke a function immediately with a chosen this; apply takes arguments as an array-like. bind returns a new function with bound this (and optional partial args) for later invocation.

  26. react

    26.What is useEffect for—and what is it not for?

    Effects synchronize with external systems (network, subscriptions, timers, non-React widgets). Do not use effects to transform data for render—compute during render. Put user-event logic in event handlers.

  27. html

    27.How should heading levels be structured?

    Use logical h1–h6 order that reflects the outline. Do not skip levels just for visual size—style with CSS. Headings are navigation landmarks for screen-reader users.

  28. css

    28.What is the difference between auto-fit and auto-fill?

    Both create as many tracks as fit. auto-fit collapses empty tracks so items can expand; auto-fill keeps empty track slots. Used with minmax for responsive grids without many breakpoints.

  29. javascript

    29.What is prototypal inheritance?

    Objects delegate property lookup along [[Prototype]]. If a property is missing, the engine walks the chain. class is syntactic sugar over constructor functions and prototypes. Footgun: mutating shared prototypes affects all instances.

  30. react

    30.How should you think about the useEffect dependency array?

    Include every reactive value the effect reads. Missing deps cause stale closures; unstable deps (new objects each render) cause loops. eslint-plugin-react-hooks exists for a reason.

  31. html

    31.What is the accessibility tree?

    A structure derived from the DOM, plus ARIA, that assistive technologies use. Broken semantics produce a poor accessibility tree even if the page “looks fine.”

    Deeper guide →

  32. css

    32.How does position: sticky work?

    The element acts relatively until a scroll threshold, then sticks within its containing block. Overflow hidden/auto on ancestors is a common reason sticky “fails.”

  33. javascript

    33.What is the difference between ==, ===, and Object.is?

    === is strict equality without coercion. == applies type coercion and is usually avoided. Object.is is like === except NaN is equal to NaN and +0 is not equal to -0.

  34. react

    34.What is a stale closure in React?

    A function captured an old props/state value from a previous render. Fix with functional updates, correct effect deps, or refs for “latest value” when intentional.

    Deeper guide →

  35. html

    35.What do native HTML5 input types buy you?

    Types like email, tel, url, number improve mobile keyboards and basic validation. They are progressive enhancement—not a substitute for server validation.

  36. css

    36.What is a stacking context?

    A local stacking order for z-index. Properties like opacity < 1, transforms, filters, and positioned elements with z-index can create new contexts—so z-index only competes inside that context.

  37. javascript

    37.What is a Promise?

    An object for a value that may arrive later: pending, then fulfilled or rejected once. Handlers run as microtasks. async/await is sugar over promises. Footgun: fetch only rejects on network failure—check response.ok for HTTP errors.

    Deeper guide →

  38. react

    38.When should you use useMemo and useCallback?

    useMemo caches expensive derived values; useCallback stabilizes function identity for memoized children or effect deps. Measure first—blind memoization adds comparison cost and noise.

  39. html

    39.What is the purpose of fieldset and legend?

    They group related controls (especially radio sets) and provide an accessible group name. Useful for screen-reader context on multi-control questions.

  40. css

    40.How does CSS specificity work?

    Roughly: inline styles > IDs > classes/attributes/pseudo-classes > elements. Equal specificity falls to source order. Cascade layers can override raw specificity between layers.

    Deeper guide →

  41. javascript

    41.When do you use Promise.all versus Promise.allSettled?

    Promise.all fails fast on the first rejection and is right when any failure should abort the batch. allSettled waits for every promise and reports each status—better when partial success is useful. Neither cancels in-flight work; pair with AbortController when needed.

    Deeper guide →

  42. react

    42.What does React.memo do?

    It skips re-rendering a component when props are shallow-equal. New inline objects/functions every render defeat it. Fix prop stability before wrapping everything in memo.

    Deeper guide →

  43. html

    43.When are HTML tables appropriate?

    For tabular data with headers—not for page layout. Use th, scope or headers/id associations so assistive tech announces relationships.

  44. css

    44.What are cascade layers (@layer) for?

    They let you order groups of styles (reset, base, components, utilities) so later layers win without escalating selector weight. Important rules reverse layer order—know that twist.

    Deeper guide →

  45. javascript

    45.Does async/await block the main thread?

    No. await pauses that async function and schedules the continuation as a microtask when the promise settles; the call stack can run other work. Heavy CPU after await still blocks—chunk work or use a worker.

    Deeper guide →

  46. react

    46.What is useRef used for?

    A mutable box that survives renders without causing re-render, and a way to hold host DOM nodes. Do not use ref reads/writes as a substitute for state that should appear on screen.

  47. html

    47.What are srcset and the picture element for?

    srcset/sizes let the browser pick among candidates by density/width. picture adds art direction (different crops by media query). Do not lazy-load the LCP image.

  48. css

    48.What are CSS custom properties good for?

    Tokens for color, space, and type that cascade and can change at runtime (theming). They are live in the cascade—unlike preprocessors variables that compile away.

  49. javascript

    49.What is AbortController and why does it matter?

    It provides a signal to cancel abortable operations like fetch. Essential when users type fast, navigate away, or race multiple requests—otherwise stale responses can overwrite newer UI state.

  50. react

    50.When do you use useLayoutEffect?

    When you must measure or mutate the DOM before the browser paints to avoid a visual flash. Prefer useEffect for most work—layout effects block paint.

Related lists

All interview question lists · Interview hub · Learn