Skip to main content

Expert JavaScript Interview Questions

Curated Expert-level JavaScript interview questions for developers targeting expert positions. 20 questions available.

Last updated:

JavaScript Interview Questions & Answers

Skip to Questions

Welcome to our comprehensive collection of JavaScript interview questions and answers. This page contains expertly curated interview questions covering all aspects of JavaScript, from fundamental concepts to advanced topics. Whether you're preparing for an entry-level position or a senior role, you'll find questions tailored to your experience level.

Our JavaScript interview questions are designed to help you:

  • Understand core concepts and best practices in JavaScript
  • Prepare for technical interviews at all experience levels
  • Master both theoretical knowledge and practical application
  • Build confidence for your next JavaScript interview

Each question includes detailed answers and explanations to help you understand not just what the answer is, but why it's correct. We cover topics ranging from basic JavaScript concepts to advanced scenarios that you might encounter in senior-level interviews.

Use the filters below to find questions by difficulty level (Entry, Junior, Mid, Senior, Expert) or focus specifically on code challenges. Each question is carefully crafted to reflect real-world interview scenarios you'll encounter at top tech companies, startups, and MNCs.

Questions

20 questions
Q1:

Explain ES6+ features used in modern JS frameworks.

Expert

Answer

Modern JS frameworks rely heavily on ES6+ features such as modules, arrow functions, template literals, destructuring, and spread/rest operators. These enhance readability, modularity, tree-shaking, and component data management.

Quick Summary: Modern JS features used in frameworks: optional chaining (?.), nullish coalescing (??), template literals, destructuring, spread/rest, async/await, Proxy/Reflect (Vue 3 reactivity), WeakRef/FinalizationRegistry (Angular change detection), Symbol.asyncIterator, dynamic import() (code splitting), and BigInt for large IDs.
Q2:

How do you manage component state in frameworks?

Expert

Answer

State is managed using hooks (React useState/useReducer), global stores like Redux/MobX, Angular services with RxJS, or NgRx. Centralized state prevents prop drilling and ensures predictable UI updates across large apps.

Quick Summary: Component state in frameworks: local state (useState in React, ref/reactive in Vue, signal in Angular) for component-specific data. Lifted state for shared parent-child data. Global store (Redux, Pinia, NgRx) for cross-component shared state. Derive state computationally (useMemo, computed) instead of duplicating. Keep state as close to where it's used as possible.
Q3:

Explain reactive programming with Observables (RxJS).

Expert

Answer

Observables represent streams of values over time. RxJS operators like map, filter, and switchMap allow transformation, cancellation, and concurrency control. Angular uses Observables extensively for HTTP, forms, and event streams.

Quick Summary: RxJS Observables represent streams of values over time — synchronous or async. subscribe() starts the stream; operators (map, filter, switchMap, debounceTime) transform it. Observable vs Promise: Observables are cancellable, produce multiple values, and are lazy (start on subscribe). switchMap cancels the previous inner observable when a new value arrives — perfect for search inputs.
Q4:

How do you handle asynchronous HTTP requests in frameworks?

Expert

Answer

React uses fetch/axios with promises or async/await. Angular uses HttpClient with Observables and operators like catchError. Proper error handling, retries, and cancellation improve reliability and avoid memory leaks.

Quick Summary: In frameworks, HTTP requests are async: React uses useEffect + fetch or SWR/React Query. Angular uses HttpClient which returns Observables — pipe through operators for retry, timeout, mapping. Vue uses Pinia + axios or VueQuery. Framework patterns: handle loading/error/success states, cancel on component unmount (AbortController / takeUntilDestroyed), deduplicate requests.
Q5:

Explain component lifecycle methods and hooks.

Expert

Answer

React uses lifecycle methods (componentDidMount, componentDidUpdate) and useEffect hook. Angular uses lifecycle hooks like ngOnInit, ngOnChanges, ngOnDestroy. They manage initialization, subscriptions, cleanup, and reactive updates.

Quick Summary: React: mounting (constructor → render → componentDidMount / useEffect[]), updating (render → componentDidUpdate / useEffect with deps), unmounting (componentWillUnmount / useEffect cleanup). Vue: created, mounted, updated, unmounted. Angular: ngOnInit, ngOnChanges, ngAfterViewInit, ngOnDestroy. Lifecycle hooks are where you initialize, clean up, and react to changes.
Q6:

How do you optimize performance in framework applications?

Expert

Answer

Techniques include lazy loading, code splitting, memoization (useMemo), pure pipes, virtual DOM optimizations, OnPush change detection, and debouncing/throttling heavy events.

Quick Summary: Framework performance: React.memo / useMemo / useCallback to prevent unnecessary re-renders, code splitting (React.lazy, dynamic imports), virtualized lists for large data, avoid large context re-renders (split contexts), Angular OnPush change detection + trackBy in ngFor, Vue computed properties + v-memo. Profile first — only optimize confirmed bottlenecks.
Q7:

Explain dependency injection in Angular.

Expert

Answer

Angular DI injects services into components instead of creating them manually. This improves modularity, testability, and code reuse. Providers can be scoped globally or to specific components.

Quick Summary: Angular DI: services are provided at root (singleton), module, or component level. Providers registered at root are singletons shared across the entire app. Provided at component level, a new instance is created per component. Services declare dependencies in their constructor — Angular's injector resolves and injects them automatically.
Q8:

What is the difference between controlled and uncontrolled components in React?

Expert

Answer

Controlled components manage form state in React. Uncontrolled components rely on the DOM for state. Controlled components provide predictable UI updates, validation, and easier debugging.

Quick Summary: Controlled: input value is driven by React state — every keystroke calls setState, React owns the value. Uncontrolled: DOM owns the value, accessed via ref.current.value. Controlled enables real-time validation, conditional disabling, and formatted inputs. Uncontrolled is simpler for basic forms but loses real-time control over input values.
Q9:

How do you handle routing in frameworks?

Expert

Answer

React Router maps URLs to components, supports nested routes and lazy loading. Angular Router uses modules, guards, resolvers, and lazy loading for scalable route management.

Quick Summary: Framework routing: React Router (client-side, JSX-based), Vue Router (official, declarative), Angular Router (built-in, module-based). All support: path matching, route params (:id), nested routes, lazy loading (loadChildren / React.lazy), route guards (auth checks before navigation), and programmatic navigation. Modern Next.js/Nuxt use file-system-based routing.
Q10:

Explain reactive forms vs template-driven forms in Angular.

Expert

Answer

Reactive forms are model-driven using FormBuilder and validators. Template-driven forms rely on directives like ngModel. Reactive forms support dynamic controls and complex validation logic.

Quick Summary: Template-driven forms (Angular): define form in HTML with ngModel — simpler, less code. Reactive forms: define form model in TypeScript (FormGroup, FormControl) — more explicit, better for complex validation, dynamic forms, and testing. Reactive forms are composable and testable; template-driven forms are quick for simple use cases. Most large Angular apps use reactive forms.
Q11:

How do you handle events efficiently in frameworks?

Expert

Answer

Use event delegation, debounce/throttle for high-frequency events, and rely on framework-specific synthetic event systems for performance and cross-browser consistency.

Quick Summary: Event handling in frameworks: React — synthetic events attached to root, cleaned up automatically. Angular — EventEmitter with @Output() for component events, HostListener for DOM events. Vue — @click handlers in template, emit() for custom events. All handle cleanup differently — React cleans up on unmount, Angular/Vue remove listeners on component destroy.
Q12:

Explain data binding types.

Expert

Answer

Angular supports one-way and two-way binding using property binding, event binding, and ngModel. React prefers one-way binding through state with explicit updates. Proper binding ensures correct UI rendering.

Quick Summary: Data binding types: One-way (parent → child via props/inputs): data flows down, changes in parent update child. Two-way: {{model}} with ngModel in Angular, v-model in Vue — input changes update state, state changes update input. Event binding (child → parent): emit events up. One-way bindings are more predictable; two-way is convenient for forms.
Q13:

What are higher-order components (HOCs) in React?

Expert

Answer

HOCs are functions that take a component and return an enhanced component. Used for cross-cutting concerns like authentication, logging, and conditional rendering.

Quick Summary: HOCs (Higher-Order Components) are functions that take a component and return a new enhanced component — adding behavior without modifying the original. Used for: auth protection (withAuth(Component)), data fetching, logging, theming. Largely replaced by React hooks (which compose behavior without wrapper components), but still used in some libraries.
Q14:

Explain Angular services and singleton behavior.

Expert

Answer

Angular services store shared logic and data. When providedIn: root is used, the service becomes a singleton, shared across the entire application unless scoped locally.

Quick Summary: Angular services provided in root (providedIn: "root") are singletons — one instance per app. Shared state (user info, API results) belongs here. Services provided at component level get a new instance per component tree. Singleton services enable data sharing between unrelated components. Lazy-loaded modules can have their own service instances.
Q15:

How do you handle lazy loading of images and modules?

Expert

Answer

Use IntersectionObserver for image lazy loading. Use React lazy()/Suspense or Angular lazy-loaded modules for code splitting and reducing initial bundle size.

Quick Summary: Image lazy loading: native HTML loading="lazy", IntersectionObserver to add src only when in viewport, or a library. Module lazy loading: dynamic import() in React (React.lazy), Angular (loadChildren: () => import(...)), Vue (defineAsyncComponent). Both defer resource loading until needed, reducing initial bundle size and improving Time to Interactive.
Q16:

Explain observables vs promises in real-world usage.

Expert

Answer

Promises handle single async responses. Observables handle multiple values, support cancellation, retries, and operators for complex async logic. Observables are ideal for dynamic event-driven applications.

Quick Summary: Observables: lazy (nothing runs until subscribe()), cancellable (unsubscribe()), emit multiple values over time, composable with operators. Promises: eager (start immediately on creation), not cancellable (except via AbortController workaround), resolve once. Use Observables for event streams and long-lived subscriptions; Promises for one-time async operations.
Q17:

How do you handle memory leaks in framework apps?

Expert

Answer

Unsubscribe from observables, remove event listeners, clear timers, use WeakMap for caching, and avoid retaining references in closures or global state.

Quick Summary: Memory leaks in frameworks: components subscribing to Observables or adding event listeners without cleaning up on destroy. React: useEffect cleanup function removes listeners. Angular: takeUntilDestroyed() or manual ngOnDestroy unsubscribe. Vue: onUnmounted() cleanup. Long-lived services that cache stale data also leak. Use DevTools heap snapshots to detect growing heap between navigations.
Q18:

Explain reactive patterns in Angular with RxJS operators.

Expert

Answer

Operators like map, filter, switchMap, mergeMap, debounceTime enable data transformation, cancellation, concurrency control, and clean async flows in Angular applications.

Quick Summary: RxJS operators in Angular: switchMap (cancel previous inner observable — search), mergeMap (run all in parallel — fire and forget), concatMap (serial, queue all — order matters), exhaustMap (ignore new while in-flight — form submit). pipe(debounceTime(300), distinctUntilChanged(), switchMap(search)) is the classic typeahead pattern.
Q19:

How do you optimize change detection in Angular?

Expert

Answer

Use OnPush strategy, immutable data structures, trackBy in ngFor, and detach change detectors when needed. Minimizes unnecessary component re-renders.

Quick Summary: Angular's default change detection (CheckAlways) checks every component on every event. OnPush strategy: only check when @Input reference changes, component emits an event, or async pipe resolves. Use OnPush with immutable state — replacing objects instead of mutating them. This cuts change detection work dramatically for large component trees.
Q20:

Best practices for integrating JavaScript with frameworks.

Expert

Answer

Separate business logic from UI, use modules/services for reusability, implement centralized state, optimize async behavior, avoid direct DOM manipulation, and follow consistent folder structure.

Quick Summary: Best practices for JS + frameworks: use TypeScript for type safety, follow framework conventions (hooks rules, OnPush, composition API), colocate component logic and template, avoid business logic in components (move to services/stores), write unit tests for services and integration tests for components, keep dependencies updated, and use framework-recommended patterns over clever workarounds.

Curated Sets for JavaScript

No curated sets yet. Group questions into collections from the admin panel to feature them here.

Ready to level up? Start Practice