P
prepair.app
Start interview →
EnglishУкраїнськаРусский
🟨

Senior JavaScriptJavaScript interview questions

Senior · 5+ years of experience

JavaScript interviews concentrate on a small number of things the language does differently from everything else: closures, `this`, prototypes and the event loop. Get those right and most other questions follow. Below are the ones asked most often, each with a model answer. Senior: architecture, trade-offs, mentoring, and decision-making.

Topics to prepare

Types and coercion
Closures and scope
`this` and prototypes
The event loop and async
Promises and async/await
DOM, events and the browser

5 Senior-level questions with answers

1

A page feels janky while scrolling. How do you diagnose it?

Answer

Record a performance profile and look at which part of the frame is over budget: script, style and layout, paint, or composite. Long tasks that block the main thread are the usual cause, and forced synchronous layout — reading a geometry property right after writing a style — is the classic self-inflicted one. Animate transform and opacity because they can be composited without layout, break long work into chunks, and move genuinely heavy computation into a Web Worker.

2

How do you think about XSS, CSP and the same-origin policy?

Answer

XSS is untrusted input becoming executable script, so the defence is contextual output encoding and never assembling HTML from strings — textContent over innerHTML. CSP is the second layer: it tells the browser which sources may execute, so an injection that slips through has nowhere to run. Same-origin policy is what stops another site reading your page or responses; CORS is the server deliberately relaxing it, not a security feature protecting the client.

3

When is a `Proxy` the right tool, and what does it cost?

Answer

It is right when you genuinely need to intercept operations you cannot enumerate ahead of time — reactivity systems, validation wrappers, mocking. It costs on every access, defeats some engine optimisations, and makes debugging harder because the object no longer behaves the way the source suggests. If a getter or a plain wrapper would do, that is the better answer.

4

ES modules versus CommonJS — what actually differs?

Answer

ESM is statically analysable: imports are resolved before execution, which is what makes tree shaking possible. CommonJS require is a runtime call, so a bundler cannot safely prove what is unused. ESM is also asynchronous and has live bindings, whereas require returns a snapshot of the exports object. The practical consequence is that mixing them, especially in Node, is where the sharp edges are.

5

How do you decide whether to add a dependency?

Answer

Weigh what it costs to ship and to maintain against what it would cost to write and own. Bundle size matters, but the bigger costs are the API surface you now depend on, the upgrade path, and what happens if it is abandoned. A small utility is usually cheaper to write than to depend on; a date library, a form library or anything touching correctness is usually cheaper to depend on than to get right yourself.

🦎

Reading answers is not enough

In a real interview you speak under pressure. Cam asks these same questions, scores every answer, and shows exactly what to fix.

Practice a Senior JavaScript interview →
Free · 3 interviews per month

Other levels — JavaScript

Junior JavaScriptMiddle JavaScriptAll JavaScript questions

Other specializations

🔍Senior Manual QA🤖Senior QA AutomationSenior Java Backend🐍Senior Python Backend🐘Senior PHP Backend🦫Senior Go Backend🟢Senior Node.js Backend💎Senior Ruby on Rails🔷Senior C++⚛️Senior React Frontend