Interview Prep | JavaScript
JavaScript Interview Questions

Entry, Mid, and Advanced JavaScript questions with short answers. Use search to filter questions quickly.

🔍

JavaScript Entry Level Q&A

Back to Top ↑
Q1. let vs const vs var?
A. var is function-scoped and hoisted. let/const are block-scoped with TDZ. const prevents reassignment.
Entry
Q2. What is a closure?
A. A function that "remembers" variables from its lexical scope even after the outer function returns.
Entry
Q3. == vs ===?
A. == coerces types; === is strict. Prefer ===.
Entry
Q4. null vs undefined?
A. undefined means not assigned; null is explicit "no value".
Entry
Q5. What is hoisting?
A. Declarations are moved conceptually to the top of scope. var becomes undefined; let/const are in TDZ.
Entry
Q6. Arrow function differences?
A. Arrow functions have lexical this and no arguments object; they cannot be used as constructors.
Entry
Q7. What is the DOM?
A. A tree representation of the document that JS can read and modify (nodes/elements).
Entry
Q8. What is event bubbling?
A. Events propagate from target up through ancestors, enabling event delegation.
Entry

JavaScript Mid Level Q&A

Back to Top ↑
🔍
Q1. What is the event loop?
A. It coordinates the call stack with task queues (macrotasks) and microtasks (Promises).
Mid
🔍
Q2. Promise.all vs Promise.allSettled?
A. all rejects on first rejection; allSettled waits and returns status for each promise.
Mid
🔍
Q3. What is async/await?
A. Syntax over Promises. async returns a Promise; await waits for settlement without blocking the thread.
Mid
🔍
Q4. What is prototypal inheritance?
A. Objects inherit via [[Prototype]] chain. Property lookup walks the prototype chain.
Mid
🔍
Q5. What is event delegation?
A. Attach one handler to a parent and handle child events via bubbling.
Mid
🔍
Q6. localStorage vs sessionStorage?
A. localStorage persists; sessionStorage is per-tab session. Both store strings synchronously.
Mid
🔍
Q7. What is CORS?
A. A browser security mechanism; servers opt in using CORS headers for cross-origin requests.
Mid
🔍
Q8. Debouncing vs throttling?
A. Debounce delays until events stop; throttle limits execution rate. Useful for scroll/input handlers.
Mid

JavaScript Advanced Level Q&A

Back to Top ↑
🧠
Q1. Microtasks vs macrotasks?
A. Microtasks (Promise callbacks) run before the next macrotask (setTimeout, I/O) tick.
Advanced
🧠
Q2. What is a memory leak in JS?
A. Unreleased references keep objects alive (globals, listeners not removed, caches).
Advanced
🧠
Q3. Garbage collection (high-level)?
A. Most engines use tracing GC; unreachable objects are collected (mark-and-sweep variants).
Advanced
🧠
Q4. Module scope and tree-shaking?
A. ES modules have their own scope; bundlers can remove unused exports (tree-shaking).
Advanced
🧠
Q5. How do you prevent XSS?
A. Escape output, avoid injecting HTML, sanitize if necessary, and use CSP.
Advanced
🧠
Q6. What is SSR hydration mismatch?
A. When server-rendered HTML differs from client render, hydration can warn or break and cause UI issues.
Advanced
🧠
Q7. What is AbortController used for?
A. To cancel fetch requests and other async operations that support abort signals.
Advanced
🧠
Q8. What is event capture?
A. Events can travel down first (capture) then bubble up; capture listeners use capture=true.
Advanced