Frontend JavaScript Interview Questions
This article compiles the most important frontend JavaScript interview questions, organized by topic and difficulty. It is designed for roles focusing on modern UI engineering, browser behavior, rendering performance, and JavaScript fundamentals.
1. Core JavaScript Fundamentals
Frontend roles require strong understanding of JS internals.
Key Topics
- Variables:
let,const,var - Hoisting
- Closures
- The
thiskeyword - Prototypal inheritance
- Modules (ESM vs CommonJS)
- Event loop basics (browser perspective)
Sample Questions
- What is hoisting? How does it apply to
var,let, andconst? - What are closures? Give 3 real-world frontend use cases.
- What does
thisrefer to inside an arrow function? - Explain the difference between shallow copy and deep copy in JS.
- What is the prototype chain? How does JS lookup properties?
2. DOM & Browser APIs
Sample Questions
- What is event bubbling vs capturing? How do you stop propagation?
- What is the difference between
DOMContentLoadedandload? - What is the difference between
innerHTML,textContent, andinnerText? - Why is direct DOM manipulation expensive?
- Explain how
querySelectorworks.
3. Event Loop (Frontend Focus)
Frontend interviews often include tricky logs involving microtasks and macrotasks.
Sample Questions
- What are microtasks and macrotasks in the browser?
- Explain the output:
js
console.log('1');
setTimeout(() => console.log('2'), 0);
Promise.resolve().then(() => console.log('3'));
console.log('4');- What is
queueMicrotaskand when would you use it? - Explain how browser rendering fits into the event loop.
- Why does long synchronous code freeze the UI?
4. CSS + Rendering + Performance
Even JS-heavy roles expect strong UI performance knowledge.
Sample Questions
- What triggers reflow vs repaint?
- Why is
getBoundingClientRect()sometimes expensive? - What is layout thrashing?
- How do you optimize animations in the browser?
- What is the difference between GPU and CPU rendering?
- Explain lazy loading. How does it work internally?
5. Async Programming
Sample Questions
- Explain callbacks vs promises vs async/await.
- Why is
try/catchtricky inside async code? - What is the difference between parallel and sequential promise execution?
- What is a race condition in JS and how do you avoid it?
- Explain
Promise.allvsPromise.racevsPromise.allSettled.
6. Web Storage & APIs
Sample Questions
- Difference between
localStorage,sessionStorage, and cookies. - What are Web Workers? Why do we need them?
- Explain CORS in the context of frontend applications.
- How does the Fetch API differ from XHR?
- What is prefetching and prerendering?
7. Security for Frontend
Sample Questions
- What is XSS? How do you prevent it?
- What is CSRF? When does it affect frontend apps?
- Why is
innerHTMLdangerous? - What is sandboxing?
- Explain Content Security Policy (CSP).
8. Framework-Specific Questions (React/Vue/Angular)
React
- How do Hooks work internally?
- What causes re-renders in React?
- What is reconciliation?
- Explain
useEffectvsuseLayoutEffect. - What is memoization in React (
useMemo,useCallback)?
Vue
- How does Vue's reactivity system track changes?
- What is a computed property?
- Difference between watchers and watchers with deep mode.
Angular
- What is change detection? How does it work?
- What is RxJS and why is it central in Angular?
- What are Angular zones?
9. Frontend Architecture & Patterns
Sample Questions
- What is a virtual DOM and why does it exist?
- What is hydration (SSR → CSR)?
- What are Web Components?
- Explain MVC vs MVVM vs Flux.
- What is tree shaking?
- What is code splitting and why is it important?
10. Debugging & Tooling
Sample Questions
- How do you debug memory leaks in the browser?
- What is a source map?
- How does the browser optimize JavaScript execution (JIT)?
- How does Chrome DevTools represent call stacks for async functions?
- What are breakpoints vs conditional breakpoints vs logpoints?
11. Coding Problems (Frontend-Oriented)
- Implement
debounce(). - Implement
throttle(). - Create a mini event emitter.
- Implement a virtualized list.
- Build a mini router using hash/history API.
- Write a function to flatten nested arrays.
- Implement lazy loading for images.
12. Take-home Assignments
- Build a simple React/Vue/Angular TODO app with persistence.
- Build a lightweight UI library with reactive updates.
- Implement infinite scroll with debouncing.
- Build a web worker–based image processor.