Skip to the page

Running a machine-coding round · mid

Vanilla JS vs React rounds

In a vanilla round, keep one state object, write a render step that updates the DOM from state, use event delegation, wrap each widget in a module or class so several instances work, and set text with textContent. In a React round, you are judged on hooks, state design and component APIs.

The notes

What you must know

  • Who asks vanilla: Flipkart machine coding (plain HTML/CSS/JS, modular), Atlassian's Karat screen (React not allowed), CRED's typeahead, Microsoft's full-page search.
  • Vanilla structure: state → render() (or targeted DOM updates) → handlers change state, then render. One listener on the container with event.target.closest('[data-id]') (event delegation) instead of one per item.
  • DOM APIs: createElement, textContent (never innerHTML with user data), DocumentFragment for batch inserts, classList, dataset, addEventListener options { once, passive, signal } (abort a controller to remove many listeners).
  • No globals: ES modules, or a factory/class per widget so two instances on one page don't share state (Front End Interview Handbook tip).
  • Performance: batch DOM writes, read layout before writing to avoid thrashing, requestAnimationFrame for animation, debounce input.
  • React: function components and hooks, minimal state, stable keys, effects with cleanup, custom hooks for logic (useDebounce, useFetch), controlled/uncontrolled APIs.
  • Both: semantic HTML, keyboard support, plain CSS (flex/grid) without frameworks.

The red pen

Common traps: mistake → fix

  • Mistake: innerHTML with user text

    Fix: XSS; use textContent or escape.

  • Mistake: A listener per list item

    Fix: memory and leaks; delegate to the container.

  • Mistake: Module-level variables for widget state

    Fix: a second instance breaks.

  • Mistake: Re-render the whole list on every keystroke in vanilla

    Fix: update only what changed or debounce.

Easy to hard

Questions interviewers ask, easy to hard

  1. Build this without React. How do you organise the code?
  2. What is event delegation and why use it here?
  3. Why is innerHTML risky?
  4. How would you support two instances of this widget on one page?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview