← All topics

JavaScript Senior interview questions and answers

75 questions for a JavaScript (Senior) interview - with correct answers, explanations and links to the docs.

Take this quiz
  1. 1.How does the event loop process tasks in the browser?
  2. 2.What happens to the page?
  3. 3.Does the new Promise(executor) executor function run synchronously?
  4. 4.Why will the promise below never reject?
  5. 5.How do you globally track unhandled promise rejections in the browser?
  6. 6.What does for await...of do?
  7. 7.What is an async generator handy for?
  8. 8.What is Proxy used for?
  9. 9.What conditions guarantee that the garbage collector will remove an object?
  10. 10.Which scenario typically causes a memory leak in an SPA?
  11. 11.Why are you advised to be careful with WeakRef and FinalizationRegistry?
  12. 12.What doesn't code inside a Web Worker have?
  13. 13.Why pass an ArrayBuffer to a worker as transferable: postMessage(buf, [buf])?
  14. 14.What can a Service Worker do?
  15. 15.How do Server-Sent Events differ from WebSocket?
  16. 16.What must you check in a message handler when talking to an iframe via postMessage?
  17. 17.How do you implement the observer pattern with browser APIs, without libraries?
  18. 18.Why is ResizeObserver better than a window.resize handler for a component?
  19. 19.What does a tagged template do?
  20. 20.In what order will Object.keys return the keys of { b: 1, 2: 1, a: 1, 1: 1 }?
  21. 21.How do you deep-freeze an object?
  22. 22.How do you serialize an object with circular references to JSON?
  23. 23.How do you limit the number of concurrent requests when loading 100 URLs?
  24. 24.What is exponential backoff when retrying requests?
  25. 25.Why is it important to preserve this and arguments in a debounce implementation?
  26. 26.Why can adding properties to objects in different orders slow code down in V8?
  27. 27.How do you avoid blocking the UI when processing 100,000 items on the main thread?
  28. 28.Why is performance.now() better than Date.now() for measuring execution time?
  29. 29.What does new Date(2025, 1, 1).getMonth() return, and which month is it?
  30. 30.What happens with 10n + 1?
  31. 31.Why does 9007199254740993 === 9007199254740992 return true?
  32. 32.What is ReDoS?
  33. 33.What's dangerous about a deep-merge function applied to user-supplied JSON?
  34. 34.Why are eval and new Function usually banned by security policy?
  35. 35.What can happen with a circular dependency between ES modules?
  36. 36.How does top-level await in a module affect the modules that import it?
  37. 37.What does Promise.withResolvers() (ES2024) give you?
  38. 38.What does new Set([1, 2, 3]).intersection(new Set([2, 3, 4])) return?
  39. 39.What does Object.groupBy(users, u => u.role) do?
  40. 40.What is MutationObserver useful for?
  41. 41.Where should you store large structured data on the client (e.g. an offline cache)?
  42. 42.How do you sync data between tabs of the same site?
  43. 43.Why cache Intl.NumberFormat instances?
  44. 44.What's the right way to build a query string from a params object?
  45. 45.What does the expression return?
  46. 46.What does [1, 2, 3, 4].findLast(n => n % 2 === 1) return?
  47. 47.Why pass the cause option to Error?
  48. 48.What is the Temporal Dead Zone for default parameters?
  49. 49.What is globalThis useful for?
  50. 50.Why shouldn't you pass an async function as the executor in new Promise(async (resolve) => ...)?
  51. 51.How do you abort a fetch after 5 seconds or when the user navigates away, whichever comes first?
  52. 52.What do iterator helpers like map.values().filter(...).take(3) give you?
  53. 53.What problem does Promise.try(fn) solve?
  54. 54.What does this regex give you?
  55. 55.What does Promise.any reject with when all promises reject?
  56. 56.What must a page do to use SharedArrayBuffer?
  57. 57.When is requestIdleCallback appropriate?
  58. 58.Why might a bundler fail to tree-shake an unused export from a library?
  59. 59.Why can this code freeze the page even though it uses promises?
  60. 60.What does Object.is(-0, 0) return, and why does it exist?
  61. 61.What does Symbol.toPrimitive control?
  62. 62.What does [] + {} evaluate to?
  63. 63.Why use Reflect.get(target, key, receiver) inside a Proxy get trap?
  64. 64.Why do schedulers (e.g. React's) use MessageChannel instead of setTimeout(fn, 0)?
  65. 65.How do CSP nonces allow specific inline scripts?
  66. 66.What do Trusted Types enforce?
  67. 67.How does SameSite=Lax on a session cookie help against CSRF?
  68. 68.What does the integrity attribute on a CDN <script> protect against?
  69. 69.What is new URL("./worker.js", import.meta.url) used for?
  70. 70.What does <script type="importmap"> enable?
  71. 71.How do you sort names correctly for a given language?
  72. 72.Why use Intl.PluralRules for messages like "5 files"?
  73. 73.What is a robust way to store and transfer dates?
  74. 74.What does a toJSON method on an object do?
  75. 75.Is Array.prototype.sort stable in modern engines?