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