Skip to main content

Salesforce Interview JavaScript Interview Questions

Curated Salesforce Interview-level JavaScript interview questions for developers targeting salesforce interview positions. 140 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

140 questions
Q1:

What is JavaScript and where is it used?

Entry

Answer

JavaScript is a high-level, interpreted programming language used to create interactive web pages.

  • Runs on browsers for client-side scripting.
  • Used on servers via Node.js.
  • Powers mobile, desktop, and game applications.
Q2:

Difference between var, let, and const.

Entry

Answer

  • var: function-scoped, redeclarable, hoisted with undefined.
  • let: block-scoped, cannot redeclare in same scope, hoisted but uninitialized.
  • const: block-scoped, cannot reassign, must initialize.
Q3:

What is hoisting in JavaScript?

Entry

Answer

Hoisting moves variable and function declarations to the top of their scope before execution. Only declarations are hoisted, not initializations.

Q4:

Difference between synchronous and asynchronous execution.

Entry

Answer

Synchronous: Executes line-by-line and blocks.

Asynchronous: Non-blocking; uses callbacks, promises, async/await.

Q5:

What is a closure?

Entry

Answer

A closure is a function that retains access to its lexical scope even after the outer function has returned.

Q6:

What are data types in JavaScript?

Entry

Answer

Primitive: String, Number, Boolean, Null, Undefined, Symbol, BigInt.

Non-primitive: Object, Array, Function.

Q7:

Difference between == and ===.

Entry

Answer

== compares values with type coercion.

=== compares value and type strictly. Prefer strict equality.

Q8:

What is the event loop?

Entry

Answer

The event loop handles asynchronous callbacks, allowing JavaScript to remain non-blocking despite being single-threaded.

Q9:

Difference between null and undefined.

Entry

Answer

null: explicitly assigned to indicate no value.

undefined: declared but not assigned.

Q10:

What are first-class functions?

Entry

Answer

Functions in JavaScript are treated as values, enabling assignment, passing as arguments, and returning from functions.

Q11:

Difference between function declaration and function expression.

Entry

Answer

Declaration is hoisted and callable before definition; expression is assigned at runtime and not hoisted the same way.

Q12:

What is the this keyword?

Entry

Answer

this refers to current execution context. Arrow functions inherit this from their parent scope.

Q13:

Difference between call, apply, and bind.

Entry

Answer

  • call: invoke with arguments list.
  • apply: invoke with arguments array.
  • bind: returns a new function with bound this.
Q14:

What is prototype in JavaScript?

Entry

Answer

Every object has a prototype from which it can inherit methods and properties.

Q15:

Difference between ES5 and ES6.

Entry

Answer

ES6 adds let/const, arrow functions, classes, modules, promises, destructuring, template literals, and more.

Q16:

What are promises?

Entry

Answer

Promises represent asynchronous results with states: pending, fulfilled, rejected.

Q17:

Explain async/await.

Entry

Answer

Async/await simplifies working with promises, making asynchronous code readable and sequential.

Q18:

Difference between shallow copy and deep copy.

Entry

Answer

Shallow copy duplicates top-level properties; deep copy recursively duplicates all nested data.

Q19:

What is the difference between let inside and outside loops?

Entry

Answer

Inside loop, let creates a new binding for each iteration, preventing closure-related bugs.

Q20:

Explain event delegation.

Entry

Answer

Event delegation uses a single parent listener to manage events for child elements using event bubbling.

Q21:

What is the difference between function scope and block scope?

Entry

Answer

Function scope: Variables declared with var are accessible throughout the function.

Block scope: Variables declared with let or const are limited to the enclosing braces {}.

Block scope reduces bugs and prevents variable leakage.

Q22:

Explain closures with real-world usage.

Entry

Answer

A closure is a function that retains access to its outer scope even after the outer function has finished executing.

Use cases: private variables, memoization, function factories, event handlers.

Q23:

What is the DOM and how does JavaScript interact with it?

Entry

Answer

The DOM represents HTML as objects. JavaScript can select, modify, create, and remove elements using DOM APIs.

Q24:

Explain event bubbling and capturing.

Entry

Answer

Bubbling: Events propagate from child to parent.

Capturing: Events propagate from parent to child.

Controlled using addEventListener(..., true).

Q25:

Difference between innerHTML, innerText, and textContent.

Entry

Answer

  • innerHTML: Reads/writes HTML.
  • innerText: Visible text only, respects CSS.
  • textContent: Raw text without parsing HTML.
Q26:

Explain template literals.

Entry

Answer

Use backticks for multi-line strings and interpolation.

`Hello ${name}`
Q27:

What are arrow functions and how do they differ from regular functions?

Entry

Answer

Arrow functions have shorter syntax, do not have their own this, and cannot be used as constructors.

Q28:

Explain higher-order functions.

Entry

Answer

Functions that receive or return other functions. Used in map, filter, reduce, and event handling.

Q29:

What is the difference between map, forEach, and filter?

Entry

Answer

  • forEach: executes callback but returns undefined.
  • map: returns a new transformed array.
  • filter: returns items that match a condition.
Q30:

Explain setTimeout vs setInterval.

Entry

Answer

setTimeout: runs code once after delay.

setInterval: runs repeatedly at intervals.

Q31:

What is the difference between synchronous and asynchronous DOM manipulation?

Entry

Answer

Synchronous DOM updates block rendering. Asynchronous updates use Promises or requestAnimationFrame to avoid UI jank.

Q32:

Explain promises and chaining.

Entry

Answer

A promise represents future completion. Chaining uses .then() and .catch() for sequential async workflows.

Q33:

What are the browser storage options in JavaScript?

Entry

Answer

localStorage: persistent key-value.

sessionStorage: session-limited key-value.

cookies: small data sent with requests, used for auth.

Q34:

Difference between synchronous and asynchronous XHR/fetch.

Entry

Answer

Synchronous blocks the main thread; asynchronous uses callbacks/promises and does not block.

Q35:

How do you handle cross-origin requests?

Entry

Answer

Browsers enforce CORS. Servers must send headers allowing specific origins.

Q36:

Explain event delegation and its benefits.

Entry

Answer

Attach listener to parent instead of each child. Better performance and supports dynamic elements.

Q37:

Difference between call, apply, and bind.

Entry

Answer

  • call: invoke with this + args list.
  • apply: invoke with this + args array.
  • bind: returns a new function with bound this.
Q38:

Difference between == and ===.

Entry

Answer

== compares with coercion; === compares type + value strictly.

Q39:

Difference between null and undefined.

Entry

Answer

null: intentional empty value.

undefined: declared but not assigned.

Q40:

What are IIFEs (Immediately Invoked Function Expressions)?

Entry

Answer

IIFEs run immediately after creation. They isolate scope and avoid global pollution.

Q41:

Explain ES6 modules and their benefits.

Junior

Answer

ES6 modules allow splitting code into separate files using export and import.

  • Better code organization
  • No global namespace pollution
  • Supports tree shaking for optimized builds
Q42:

Difference between default export and named export.

Junior

Answer

Default export: One per module, imported without braces.

Named export: Multiple per module, imported using braces.

Q43:

Explain template literals and tagged templates.

Junior

Answer

Template literals use backticks for interpolation and multi-line strings.

Tagged templates allow processing template literals with custom functions.

Q44:

What are destructuring assignments?

Junior

Answer

Destructuring extracts values from arrays or objects into variables.

Q45:

Explain rest and spread operators.

Junior

Answer

Rest (...): collects remaining elements.

Spread (...): expands iterable elements.

Q46:

What are default parameters in functions?

Junior

Answer

Allows functions to use default values when arguments are missing.

Q47:

Explain arrow functions and lexical this.

Junior

Answer

Arrow functions inherit this from the surrounding scope, making them ideal for callbacks.

Q48:

Difference between let, const, and var in ES6.

Junior

Answer

var: function-scoped.

let: block-scoped.

const: block-scoped, cannot reassign.

Q49:

Explain promises and chaining in ES6+.

Junior

Answer

Promises represent async completion. Chaining uses .then() and .catch() for sequential workflow.

Q50:

Explain async/await syntax.

Junior

Answer

async functions return promises. await pauses execution until promise resolves.

Q51:

Difference between microtasks and macrotasks.

Junior

Answer

Microtasks: Promises, queueMicrotask.

Macrotasks: setTimeout, setInterval, I/O.

Q52:

Explain the event loop in JavaScript.

Junior

Answer

The event loop manages asynchronous execution, processing synchronous code, microtasks, then macrotasks.

Q53:

What is the difference between shallow and deep copy?

Junior

Answer

Shallow copy: top-level copy.

Deep copy: recursive copy without shared references.

Q54:

Explain Symbol and its use cases.

Junior

Answer

Symbol is a unique primitive used for unique object keys and meta-programming.

Q55:

Explain Set and Map in ES6.

Junior

Answer

Set: stores unique values.

Map: stores key-value pairs with any type of key.

Q56:

What are WeakMap and WeakSet?

Junior

Answer

Store weak references to objects, allowing garbage collection. Useful for memory-sensitive caching.

Q57:

Explain generators and yield.

Junior

Answer

Generators pause/resume execution using yield. Useful for lazy evaluation and iterators.

Q58:

Explain modules vs global scripts.

Junior

Answer

Modules have their own scope; global scripts share the global namespace.

Q59:

How are errors handled in async JavaScript?

Junior

Answer

Use .catch() with promises and try/catch with async/await.

Q60:

Explain memory management in JavaScript.

Junior

Answer

JavaScript uses automatic garbage collection. Developers must avoid leaks by cleaning listeners, closures, and timers.

Q61:

What are Web APIs in JavaScript?

Mid

Answer

Web APIs provide browser-based functionalities accessible to JavaScript.

Examples include:

  • DOM API
  • Fetch API
  • Web Storage
  • WebSockets
  • Canvas API
  • Service Workers

They enable dynamic, interactive, and offline-capable web applications.

Q62:

Explain the Fetch API and its advantages over XMLHttpRequest.

Mid

Answer

The Fetch API is promise-based and easier to work with than XMLHttpRequest.

  • Simpler syntax and chaining
  • Returns Response objects
  • Better error handling
  • Supports streaming and CORS
Q63:

What are Service Workers and why are they important?

Mid

Answer

Service workers run in the background, independent of web pages.

  • Enable offline support
  • Implement caching strategies
  • Handle push notifications
  • Provide background sync

They form the foundation of Progressive Web Apps (PWAs).

Q64:

Explain WebSockets and their use cases.

Mid

Answer

WebSockets provide full-duplex communication over a single TCP connection.

Use cases include:

  • Real-time chat
  • Live stock updates
  • Gaming
  • Live dashboards
Q65:

Difference between localStorage, sessionStorage, and IndexedDB.

Mid

Answer

  • localStorage: Persistent key-value storage.
  • sessionStorage: Data persists for session only.
  • IndexedDB: Client-side NoSQL database for structured data.
Q66:

Explain requestAnimationFrame and its importance.

Mid

Answer

requestAnimationFrame syncs animations with browser repaint cycles.

Improves smoothness and reduces CPU usage compared to timers.

Q67:

How to improve DOM performance?

Mid

Answer

  • Minimize reflows and repaints
  • Use document fragments
  • Batch DOM updates
  • Cache selectors
  • Avoid layout thrashing
Q68:

What is Debouncing and Throttling?

Mid

Answer

Debouncing: Trigger function after a delay of inactivity.

Throttling: Trigger function at fixed intervals.

Useful for scroll, resize, and search inputs.

Q69:

Explain memory leaks in JavaScript and how to avoid them.

Mid

Answer

Memory leaks occur when unused objects remain referenced.

  • Dangling references
  • Uncleared timers
  • Unremoved event listeners
  • Closures holding unnecessary data

Remove listeners, clear intervals, and nullify unused references.

Q70:

Difference between synchronous and asynchronous APIs.

Mid

Answer

Synchronous: Execution blocks until complete.

Asynchronous: Returns immediately, uses callbacks or promises.

Q71:

What are design patterns in JavaScript?

Mid

Answer

Design patterns are reusable solutions to common problems.

  • Module
  • Singleton
  • Observer
  • Factory
  • MVC
Q72:

Explain the Module Pattern.

Mid

Answer

Module pattern encapsulates private variables using closures.

Exposes only public methods, preventing namespace pollution.

Q73:

Explain the Observer Pattern.

Mid

Answer

The observer pattern allows objects to subscribe to changes in another object.

Useful for events, data binding, and reactive programming.

Q74:

Difference between Singleton and Factory Patterns.

Mid

Answer

Singleton: Only one instance allowed.

Factory: Creates objects without exposing creation logic.

Q75:

What is lazy loading in JavaScript?

Mid

Answer

Lazy loading delays loading non-critical resources until needed.

Used for images, scripts, and modules to improve load time.

Q76:

Explain async iterators and for-await-of.

Mid

Answer

Async iterators allow iteration over asynchronous data streams.

for-await-of simplifies consuming async sequences.

Q77:

Explain Web Workers.

Mid

Answer

Web Workers run scripts in background threads.

Prevent blocking the main UI thread during heavy computations.

Q78:

How is security handled in JavaScript on the client side?

Mid

Answer

  • Sanitize inputs to prevent XSS
  • Use HTTPS
  • Implement CSP
  • Prevent CSRF
Q79:

Difference between event capturing and bubbling.

Mid

Answer

Capturing: Event flows parent ? child.

Bubbling: Event flows child ? parent.

Q80:

How do you optimize JavaScript performance?

Mid

Answer

  • Minimize DOM operations
  • Use event delegation
  • Apply lazy loading
  • Debounce/throttle events
  • Prevent memory leaks
  • Split code into modules
Q81:

Explain the difference between synchronous and asynchronous programming.

Senior

Answer

Synchronous programming executes code line by line, blocking execution until each task finishes.

Asynchronous programming allows code to run without blocking, enabling concurrent operations such as network calls, timers, or file I/O.

This is essential for responsive and non-blocking web applications.

Q82:

How do you avoid callback hell?

Senior

Answer

Callback hell occurs from deeply nested callbacks. Solutions include:

  • Promises – chain operations instead of nesting.
  • Async/await – write asynchronous code in synchronous style.
  • Modular functions – split logic into reusable functions.
Q83:

Explain promise chaining with error handling.

Senior

Answer

Promise chaining allows sequential async operations using .then().

Errors propagate through the chain until handled by .catch(), preventing further execution.

Q84:

What is the difference between microtasks and macrotasks?

Senior

Answer

Microtasks: Executed immediately after current execution stack (Promises, queueMicrotask).

Macrotasks: Executed in next event loop turn (setTimeout, setInterval, I/O).

Crucial for understanding async flow and ordering.

Q85:

How are async iterators used in JavaScript?

Senior

Answer

Async iterators allow iteration over asynchronous data streams using for-await-of.

Useful for consuming streamed data or paginated API results.

Q86:

Explain the Observer pattern in JavaScript.

Senior

Answer

The Observer pattern enables one-to-many communication where observers are notified on state changes.

Widely used in event systems, reactive UIs, and data-binding frameworks.

Q87:

What is the Publisher-Subscriber pattern?

Senior

Answer

Pub-Sub decouples senders (publishers) from receivers (subscribers) through a central event hub.

Useful for modular architectures, micro frontends, and Node.js event emitters.

Q88:

Explain throttling and debouncing for async event handling.

Senior

Answer

Throttling: Ensures function runs at most once per interval.

Debouncing: Delays execution until activity has stopped.

Used to optimize scroll, resize, and input-heavy interactions.

Q89:

Difference between promises, async/await, and callbacks.

Senior

Answer

  • Callbacks: Basic async, but prone to nesting and complexity.
  • Promises: Provide cleaner chaining and error handling.
  • Async/await: Makes async code look synchronous for readability.
Q90:

Explain memory management in asynchronous code.

Senior

Answer

Async operations may retain references via closures, causing memory leaks.

  • Clear timers and intervals
  • Abort unused fetch requests
  • Remove event listeners
  • Nullify long-lived references
Q91:

How do you handle API errors in JavaScript?

Senior

Answer

Use try/catch for async/await or .catch() for promises.

Differentiate between:

  • Network errors
  • HTTP status failures
  • Logical/validation errors
Q92:

Explain service workers and caching strategies.

Senior

Answer

Service workers run in background threads and enable offline capabilities.

Caching strategies include:

  • Cache-first – load from cache, update later
  • Network-first – fetch first, fallback to cache
Q93:

Difference between web workers and service workers.

Senior

Answer

Web Workers: CPU-intensive tasks, no DOM access.

Service Workers: Handle caching, offline, and network interception.

Q94:

Explain lazy loading of modules and resources.

Senior

Answer

Lazy loading delays non-critical modules until needed.

Reduces initial load time and improves page performance.

Q95:

What is the revealing module pattern?

Senior

Answer

Encapsulates private data in closures and exposes only selected public methods.

Enhances modularity and maintains clean global scope.

Q96:

How do you prevent race conditions in async operations?

Senior

Answer

  • Use sequential await
  • Implement locks or semaphores
  • Avoid shared mutable state
  • Use atomic operations
Q97:

Difference between shallow copy and deep copy in async operations.

Senior

Answer

Shallow copy: Copies top-level properties; nested references remain shared.

Deep copy: Recursively copies all properties.

Deep copies prevent async operations from interfering with each other.

Q98:

What are ES6 symbols and their use in async patterns?

Senior

Answer

Symbols are unique, immutable identifiers.

Used for private object keys or internal async state to avoid naming collisions.

Q99:

How do you debug asynchronous JavaScript?

Senior

Answer

  • Use browser DevTools async stack traces
  • Insert breakpoints in async code
  • Use VSCode/Node.js debugger
  • Log promise resolution paths
Q100:

Best practices for high-performance asynchronous JavaScript.

Senior

Answer

  • Minimize DOM manipulation in async tasks
  • Use throttling and debouncing
  • Prefer async/await over nested promises
  • Use Web Workers for heavy computations
  • Clean up timers and event listeners
Q101:

Explain closures in large applications.

Senior

Answer

Closures allow functions to retain access to variables in their outer lexical environment, even after the outer function has executed. They are useful for encapsulation, private states, and modular structure in large apps. However, uncontrolled closures can lead to memory leaks when references persist longer than needed. Proper cleanup and scoped design help mitigate risks.

Q102:

What is the Revealing Module Pattern and why use it?

Senior

Answer

The Revealing Module Pattern encapsulates private variables and functions, exposing only selected methods or properties as the module’s public API. It improves maintainability, reduces global scope pollution, and enforces clean architecture in large applications.

Q103:

How do you manage namespaces in large JS projects?

Senior

Answer

Namespaces prevent global scope pollution by grouping related functions or modules together. Approaches include ES6 modules, IIFEs, or object-based namespaces. This improves maintainability and prevents naming conflicts in large applications.

Q104:

Explain event delegation at scale.

Senior

Answer

Event delegation attaches one listener to a parent element and uses event bubbling to manage child interactions. It improves performance, reduces memory usage, and handles dynamic DOM updates efficiently, especially in data-heavy UIs like tables and lists.

Q105:

How do you optimize DOM manipulation in large applications?

Senior

Answer

Optimization includes batching DOM updates, using requestAnimationFrame, minimizing reflows/repaints, document fragments, and caching DOM references. Reduces performance bottlenecks in large-scale applications.

Q106:

Explain virtual DOM concept in frameworks.

Senior

Answer

The virtual DOM is an in-memory representation of the UI. Frameworks compute diffs between old and new virtual trees and update only changed parts of the real DOM. This drastically improves rendering performance in complex UIs.

Q107:

What are async patterns in large applications?

Senior

Answer

Patterns include Promises, async/await, observables, event-driven architecture, and concurrency handling via Promise.all or race conditions. Ensures scalable and responsive user interfaces.

Q108:

Explain memoization and its benefits.

Senior

Answer

Memoization caches results of expensive computations, improving performance when functions are repeatedly executed with the same inputs. Often used in UI rendering optimization or heavy computations.

Q109:

How do you manage API calls efficiently in large apps?

Senior

Answer

Techniques include caching responses, debouncing/throttling requests, batching, retry strategies, cancellation tokens, and centralized error handling. These reduce network overhead and improve user experience.

Q110:

What are design patterns commonly used in JavaScript?

Senior

Answer

Common patterns include Module, Revealing Module, Singleton, Factory, Observer, and Pub-Sub. They provide reusable solutions for complex architectural problems in large-scale JavaScript applications.

Q111:

Explain memory management in large-scale JavaScript applications.

Senior

Answer

Memory management requires avoiding leaks caused by closures, unremoved event listeners, stale references, and long-running timers. Tools like Chrome Memory profiler help detect leaks, ensuring long-running app stability.

Q112:

What are Web Workers and why are they important in large apps?

Senior

Answer

Web Workers allow CPU-heavy tasks to run in background threads, preventing the main thread from blocking. Essential for large apps needing image processing, analytics, or real-time data operations.

Q113:

How do you implement lazy loading of modules or components?

Senior

Answer

Lazy loading loads resources only when needed using dynamic imports, code-splitting, or IntersectionObserver for assets. Reduces initial page load time and improves performance.

Q114:

Explain throttling and debouncing in performance optimization.

Senior

Answer

Throttling limits how often a function executes within time intervals. Debouncing delays execution until inactivity. Both reduce unnecessary operations in scroll, resize, and input events.

Q115:

How do you handle state management in large-scale JS apps?

Senior

Answer

State can be managed using Redux, MobX, Zustand, Context API, or observable-based patterns. Ensures predictable updates and avoids prop drilling in complex components.

Q116:

Explain async iteration and streams.

Senior

Answer

Async iterators allow sequential handling of asynchronous data streams using for-await-of. Useful for paginated APIs or real-time feeds. Provides clear and controlled async flow.

Q117:

How do you prevent race conditions in async operations?

Senior

Answer

Use locking mechanisms, sequential awaits, atomic operations, or cancellation tokens. Prevents inconsistent updates when multiple async tasks modify shared resources.

Q118:

Explain module bundling and tree shaking.

Senior

Answer

Bundlers like Webpack, Vite, or Rollup merge multiple modules into optimized bundles. Tree shaking removes unused exports, reducing bundle size and improving load performance.

Q119:

How do you profile and debug large-scale JS apps?

Senior

Answer

Use Chrome DevTools for performance/memory profiling, inspect async call stacks, evaluate network usage, and detect memory leaks. Tools like Lighthouse and VSCode debugger provide deep insights.

Q120:

Best practices for writing maintainable large-scale JavaScript.

Senior

Answer

Use modular structure, consistent naming, ES6+ features, linting, type checking, state management, and performance optimization techniques. Ensures scalability, testability, and maintainability in enterprise applications.

Q121:

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.

Q122:

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.

Q123:

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.

Q124:

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.

Q125:

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.

Q126:

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.

Q127:

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.

Q128:

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.

Q129:

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.

Q130:

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.

Q131:

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.

Q132:

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.

Q133:

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.

Q134:

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.

Q135:

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.

Q136:

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.

Q137:

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.

Q138:

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.

Q139:

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.

Q140:

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.

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