Interview Q&A · JavaScript · 12 questions in this topic

Performance & Memory — JavaScript Interview Q&A

All JavaScript topics

Fast JavaScript — rendering performance, bundle cost, GC behavior and measurement discipline. Part of Performance & Memory · 204 questions in the JavaScript bank.

How do you find what is slow (measure-first workflow)?

Answer

Profile before optimizing: DevTools Performance (flame charts, long tasks), Lighthouse/Web-Vitals (field + lab), memory snapshots (retention paths), and bundleanalyzer for bytes. One bottleneck at a time, re-measure every change.

Flame-first beats guess-first every time.

Key points

  1. 1Profile — flame charts, long tasks.
  2. 2Field — Core Web Vitals (LCP/INP/CLS).
  3. 3Bytes — bundle analysis.

💡 INP-plus-LCP-plus-CLS is the vitals trio to name.

How do you reduce bundle size (code-splitting, tree-shaking)?

Answer

Route-level dynamic import() splits, named ESM exports shake, sideEffects flags guide bundlers, dependency audits (one date lib, not three) cut vendor weight, and compression (brotli) plus caching headers finish delivery. Budget via performance budgets in CI.

Split-routes, shake-dead, audit-vendor is the bytes doctrine.

Example

Example.jsjs
const Admin = lazy(() => import('./Admin.js')); // route split

💡 Dynamic-import-at-routes is the highest-leverage split.

How do virtualized lists handle huge datasets?

Answer

Render only visible rows (windowed) with measured/estimated heights, recycling DOM nodes on scroll — 100k rows feel like 20. Libraries (react-window, TanStack Virtual) handle measurement, overscan and dynamic heights.

Window-visible-only is the virtualization principle.

Example

Example.jsjs
// TanStack Virtual sketch: rows absolute-positioned in a tall spacer

Recommended resourcesAffiliate links · may earn us a commission

Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Cloud hosting for side projectsShip the portfolio project that gets you hired — free credits for new accounts.Claim credits