Skip to content

Rapid Fire (100)

1. let vs var vs const

var: function-scoped, hoisted as undefined. let/const: block-scoped, hoisted but in the TDZ. const: can’t be reassigned (objects can still be mutated).

2. == vs ===

== converts types before comparing; === compares value and type with no conversion. Use ===.

3. What is a closure?

A function that remembers variables from the scope where it was created, even after that scope has finished.

4. What is hoisting?

Declarations are processed before code runs. var → undefined, functions → fully available, let/const → TDZ.

5. What is the event loop?

Runs the call stack; when it’s empty, drains ALL microtasks (promises), then takes ONE macrotask (setTimeout, I/O), and repeats.

6. Microtask vs macrotask?

Microtasks: Promise.then, queueMicrotask, MutationObserver. Macrotasks: setTimeout, setInterval, I/O, UI events. Microtasks always go first.

7. What is `this`?

Depends on how a function is called: obj.method() → obj; plain call → undefined (strict mode); new → the new object; arrow functions → this from the enclosing scope.

8. call vs apply vs bind

call(thisArg, a, b), apply(thisArg, [a, b]) invoke immediately; bind returns a new function with this fixed.

9. Arrow vs regular function?

Arrow: no own this/arguments, can’t be used with new, no prototype. Good for callbacks.

10. What is a Promise?

An object representing a future value: pending → fulfilled or rejected. Chain with .then/.catch or await.

11. Promise.all vs allSettled vs race vs any

all: all succeed, or fails on the first rejection. allSettled: waits for all, never rejects. race: first to settle. any: first to fulfill.

12. null vs undefined

undefined: declared but not assigned (set by JS). null: intentionally empty (set by you). typeof null === ‘object’ (a historical bug).

13. Shallow vs deep copy

Shallow copies top-level only (spread, Object.assign). Deep copies nested too: structuredClone().

14. What is a prototype?

Every object links to another object (its prototype); property lookup walks up this chain. Classes are syntax on top of prototypes.

15. Debounce vs throttle

Debounce: run after the user STOPS for X ms (search input). Throttle: run at most once per X ms (scroll, resize).

16. Event bubbling vs capturing

Capturing: window → target. Bubbling: target → window (default). stopPropagation stops it.

17. Event delegation

Attach one listener to a parent and use event.target to handle events from many children. Fewer listeners, and it works for elements added later.

18. ES modules vs CommonJS

ESM: import/export, static, can be tree-shaken, async loading. CJS: require/module.exports, dynamic, synchronous, Node’s original system.

19. What is a pure function?

Same input → same output, no side effects. Easy to test; React expects components to be pure.

20. map vs forEach

map returns a new array; forEach returns undefined and is used for side effects.

21. What is the virtual DOM?

A JS representation of the UI. On state change, React diffs the new tree with the old one (reconciliation) and applies minimal real DOM updates.

22. Why do lists need keys?

So React can match items between renders. Index keys break when items are reordered or inserted, giving wrong state and extra re-renders.

23. What triggers a re-render?

State change, parent re-render, or a context value change. (Props changing is a consequence of the parent re-rendering.)

24. useEffect dependency array

No array: runs after every render. []: once on mount. [a,b]: when a or b change. The cleanup runs before the next effect and on unmount.

25. useMemo vs useCallback

useMemo caches a computed VALUE; useCallback caches a FUNCTION reference. Use them only for expensive work or stable props to memoized children.

26. What does React.memo do?

Skips re-rendering a component if its props are shallowly equal to the previous props.

27. useRef uses

Accessing DOM nodes, and storing mutable values that persist across renders WITHOUT causing a re-render (timers, previous values).

28. Controlled vs uncontrolled input

Controlled: value lives in React state. Uncontrolled: the DOM holds the value; read it via ref/FormData.

29. Rules of hooks

Call them only at the top level (not in loops/conditions) and only from components/custom hooks. React relies on call order.

30. Context vs Zustand

Context re-renders all consumers on any change; Zustand re-renders only components whose selected slice changed.

31. Why does StrictMode run effects twice?

In development only, it mounts → unmounts → mounts to surface missing cleanup. Production runs effects once.

32. What is lifting state up?

Moving shared state to the closest common parent and passing it down via props.

33. What are error boundaries?

Class components (or a library) that catch render errors in children and show a fallback UI. They don’t catch errors in event handlers or async code.

34. What is Suspense?

Shows a fallback while children are waiting (lazy components, data with use()/frameworks).

35. What is prop drilling, and how do you fix it?

Passing props through many layers that don’t use them. Fixes: composition (children), Context, or a store.

36. Server vs client components

Server: render on the server, can fetch data/access the DB, ship no JS. Client (‘use client’): need state, effects, browser APIs, event handlers.

37. SSR vs SSG vs ISR vs CSR

SSR: HTML per request. SSG: HTML at build. ISR: static + regenerated after a revalidate time. CSR: browser renders after JS loads.

38. What does 'use client' do?

Marks a boundary: this file and its imports become part of the client bundle.

39. What are server actions?

Async functions marked ‘use server’ that run on the server, called directly from forms/components. Used for mutations.

40. What is middleware used for?

Runs before a request is completed: auth redirects, rewrites, locale, headers.

41. How do you revalidate data?

Time-based: fetch(url, { next: { revalidate: 60 } }). On demand: revalidatePath() / revalidateTag() after a mutation.

42. What does OpenNext do?

Adapts Next.js build output to run on non-Vercel platforms like Cloudflare Workers or AWS.

43. Is Node single-threaded?

JS runs on one thread; libuv uses a thread pool for fs, DNS, crypto, and zlib; the OS handles network I/O asynchronously.

44. process.nextTick vs setImmediate

nextTick runs before other microtasks/promises, right after the current operation. setImmediate runs in the check phase after I/O.

45. What is middleware in Express?

A function (req, res, next) in the request pipeline. It can modify req/res, end the response, or call next().

46. How do you handle errors in Express?

Error middleware with 4 args (err, req, res, next). In Express 5, rejected promises are passed to it automatically; in v4, use try/catch + next(err).

47. PUT vs PATCH

PUT replaces the whole resource (idempotent). PATCH partially updates.

48. What does idempotent mean?

Doing it N times has the same effect as once. GET, PUT, DELETE are idempotent; POST isn’t.

49. 401 vs 403

401: not authenticated (who are you?). 403: authenticated but not allowed.

50. Status codes to know

200 OK, 201 Created, 204 No Content, 301/302 redirect, 304 Not Modified, 400, 401, 403, 404, 409 Conflict, 422, 429 Too Many Requests, 500, 502, 503.

51. REST vs GraphQL

REST: multiple endpoints, fixed responses, easy HTTP caching. GraphQL: one endpoint, the client picks fields; solves over/under-fetching but makes caching harder.

52. What is CORS?

A browser security rule: JS can’t read cross-origin responses unless the server sends Access-Control-Allow-Origin. Non-simple requests send a preflight OPTIONS.

53. What are Cloudflare Workers?

Serverless functions running in V8 isolates at the edge. Near-zero cold start, Web-standard APIs, CPU-time limits.

54. Why Hono?

Tiny, fast, built on Web Standards, so it runs on Workers/Bun/Deno/Node; Express-like middleware, great TypeScript.

55. What are streams in Node?

Process data in chunks instead of loading it all into memory: readable, writable, duplex, transform. Use pipe/pipeline.

56. How do you scale Node on multiple cores?

The cluster module / PM2 (multiple processes), or multiple containers behind a load balancer. Worker threads for CPU-heavy tasks.

57. What is rate limiting?

Restricting requests per client per time window to prevent abuse. Algorithms: fixed window, sliding window, token bucket. Return 429.

58. SQL vs NoSQL

SQL: schema, relations, joins, ACID, good for structured data. NoSQL: flexible schema, scales horizontally easily, good for documents/high write volume.

59. What is an index?

A data structure (usually a B-tree) that makes lookups fast, like a book index. It costs storage and slows writes.

60. When does an index NOT help?

Small tables, low-selectivity columns (e.g., boolean), functions on the column, a leading wildcard LIKE ‘%x’, or not using the leftmost column of a composite index.

61. What is ACID?

Atomicity (all or nothing), Consistency (constraints hold), Isolation (concurrent transactions don’t interfere), Durability (committed = saved).

62. What is a transaction?

A group of queries that succeed or fail together: BEGIN … COMMIT / ROLLBACK.

63. What is the N+1 problem?

1 query for a list + N queries for each item’s relation. Fix with a JOIN, an IN (…) batch query, or the ORM’s eager loading.

64. What is normalization?

Organizing tables to remove duplication: 1NF atomic values, 2NF no partial dependency, 3NF no transitive dependency.

65. INNER vs LEFT JOIN

INNER: only rows matching in both tables. LEFT: all rows from the left table, NULLs where there’s no match.

66. WHERE vs HAVING

WHERE filters rows before grouping; HAVING filters groups after GROUP BY.

67. Why connection pooling?

Opening DB connections is expensive; a pool reuses open connections. Critical for serverless (Hyperdrive, PgBouncer).

68. What is RLS?

Row Level Security: Postgres policies that restrict which rows a user can read/write. This is what makes Supabase safe.

69. Embedding vs referencing in MongoDB

Embed data that’s read together and bounded (1-to-few). Reference data that’s unbounded or shared (1-to-many, many-to-many).

70. Offset vs cursor pagination

Offset: simple, but slow at large offsets and shifts when data changes. Cursor: WHERE id < last_id, fast and stable.

71. Authentication vs authorization

AuthN = who you are (login). AuthZ = what you’re allowed to do (roles/permissions).

72. JWT structure

header.payload.signature, base64url-encoded. SIGNED, not encrypted: anyone can read the payload.

73. Session vs JWT

Session: server stores state, easy to revoke. JWT: stateless and scales easily, but hard to revoke before expiry.

74. Where should you store tokens?

An httpOnly + Secure + SameSite cookie. localStorage is readable by any XSS script.

75. Access + refresh tokens

A short-lived access token (~15 min) plus a long-lived refresh token to get new ones. Limits damage if a token is stolen.

76. How should passwords be stored?

Hashed with bcrypt/argon2 (slow, salted). Never plain text, never fast hashes like MD5/SHA256 alone.

77. What is XSS, and how do you prevent it?

Injected scripts run in a victim’s browser. Prevent with output escaping (React does this by default), avoiding dangerouslySetInnerHTML, CSP, and httpOnly cookies.

78. What is CSRF, and how do you prevent it?

Another site makes the browser send an authenticated request using its cookies. Prevent with SameSite cookies, CSRF tokens, and checking Origin.

79. What is SQL injection, and how do you prevent it?

User input is interpreted as SQL. Prevent with parameterized queries/ORMs; never concatenate strings.

80. OAuth in one line

Lets a user grant your app limited access via a provider (Google) without giving you their password. You exchange an authorization code for tokens.

81. What happens when you type a URL?

DNS lookup → TCP + TLS handshake → HTTP request → server response → browser parses HTML → builds DOM/CSSOM → layout → paint; JS/CSS fetched along the way.

82. What is a CDN?

Servers worldwide that cache content close to users, giving lower latency and less load on the origin.

83. WebSocket vs SSE vs polling

WebSocket: two-way, persistent. SSE: server → client only, over HTTP, auto-reconnect. Polling: repeated requests, simple but wasteful.

84. What is HLS?

Video split into small segments at multiple qualities, with an .m3u8 playlist. The player switches quality based on bandwidth.

85. HTTP/1.1 vs HTTP/2 vs HTTP/3

HTTP/2: multiplexing many requests on one connection, header compression. HTTP/3: runs over QUIC (UDP), no TCP head-of-line blocking.

86. Cache-Control basics

max-age=N: cache for N seconds. no-cache: revalidate first. no-store: never cache. ETag + 304 for revalidation.

87. Docker image vs container

An image is a read-only template (a class); a container is a running instance of it (an object).

88. Git merge vs rebase

Merge keeps history and adds a merge commit. Rebase replays your commits on top for a linear history. Never rebase shared/pushed branches.

89. git reset vs git revert

reset moves the branch pointer (rewrites history, local use). revert adds a new commit that undoes one (safe for shared branches).

90. Horizontal vs vertical scaling

Vertical: a bigger machine. Horizontal: more machines behind a load balancer (needs stateless servers).

91. Hash map lookup complexity

Average O(1), worst case O(n).

92. Binary search requirement

Sorted data (or a monotonic condition). O(log n).

93. Sorting complexity

Comparison sorts take O(n log n) at best. Java’s Arrays.sort uses dual-pivot quicksort for primitives and TimSort for objects.

94. BFS vs DFS

BFS uses a queue and finds the shortest path in unweighted graphs. DFS uses a stack/recursion and is used for paths, cycles, and components.

95. When to use a heap

Top K, kth largest, merging sorted lists, scheduling. Insert/poll O(log n), peek O(1).

96. Stack use cases

Matching brackets, undo, DFS, monotonic stack (next greater element).

97. Sliding window signal

Contiguous subarray/substring with a condition (longest/shortest/max sum of size k).

98. Two pointers signal

Sorted array, pairs/triplets, in-place removal, palindromes.

99. What is dynamic programming?

Recursion + caching overlapping subproblems. Define state, transition, base case.

100. Array vs linked list

Array: O(1) index access, O(n) insert in the middle. Linked list: O(1) insert at a known node, O(n) access.