Interview Prep Guide

JavaScript Interview Questions and Answers for Freshers to Experienced Developers

Prepare for JavaScript interviews with practical questions about variables, closures, async behavior, event loop concepts, and coding rounds.

Basic JavaScript Interview Questions

  1. What is the difference between var, let, and const?

    var is function-scoped and can be redeclared, while let and const are block-scoped. const cannot be reassigned after initialization.

  2. What is the difference between == and ===?

    == performs type coercion before comparison, while === compares both value and type without coercion.

  3. What is hoisting in JavaScript?

    Hoisting refers to how declarations are processed before execution, which is why some functions and variables behave as if they are available earlier than their written position.

  4. What is the difference between null and undefined in JavaScript?

    undefined means a variable has been declared but not assigned, while null is an intentional assignment representing "no value".

Medium JavaScript Interview Questions

  1. What is a closure in JavaScript?

    A closure happens when a function remembers variables from its outer lexical scope even after the outer function has finished executing.

  2. How do promises and async-await relate to each other?

    async-await is syntax built on top of promises that makes asynchronous code read more like sequential code.

  3. How is this determined in JavaScript?

    The value of this depends on how a function is called, not where it is written. It can point to an object, be undefined in strict mode, or be lexically captured by arrow functions.

  4. What are higher-order functions in JavaScript?

    Higher-order functions are functions that take other functions as arguments or return them as results, such as map, filter, and reduce.

Advanced JavaScript Interview Questions

  1. How does the event loop affect JavaScript execution order?

    The event loop coordinates the call stack and queued tasks, which determines when synchronous code, microtasks, and macrotasks execute.

  2. How does prototypal inheritance work in JavaScript?

    Objects can inherit properties and methods through their prototype chain, allowing property lookup to continue upward when a key is not found on the object itself.

  3. How do ES modules differ from CommonJS modules?

    ES modules use static import/export syntax that can be analyzed before execution, while CommonJS uses require and module.exports at runtime.

  4. What is Currying in JavaScript?

    Currying is a functional programming technique where a function with multiple arguments is transformed into a sequence of functions, each taking a single argument.

Scenario-Based JavaScript Interview Questions

  1. How would you debug a frontend bug where API data sometimes appears in the wrong order or updates the UI after the user has already changed screens?

    Think about asynchronous timing, stale closures, race conditions, and whether older requests are still allowed to update current UI state.

JavaScript Coding Round

  1. Implement debounce or flatten nested arrays

    These prompts often reveal whether you understand function scope and async timing. Even if you know the pattern already, interviewers still watch how clearly you explain the trade-offs and test edge cases.

  2. Implement a Throttle function

    Unlike debounce (which waits for a pause), throttling ensures a function runs at most once every X milliseconds. A strong solution uses a flag or a timestamp to track the last execution and ensures subsequent calls are ignored until the period expires. This is critical for performance in scroll or resize handlers.

  3. Implement debounce or async request coordination for a search input

    Interviewers usually want code that is easy to explain. Strong answers make timer behavior explicit, avoid stale-state bugs, and describe how the solution improves both UX and network efficiency.