JavaScript Interview Questions and Answers

JavaScript is asked about in almost every frontend and full stack interview, and in many backend ones that use Node.js. These questions start with the fundamentals that interns and freshers are expected to know and move up to the event loop, prototypes and memory management that senior interviews probe.

Usually asked in frontend and full stack interviews, from intern / fresher to senior (5+ years).

Intern / Fresher

  1. Q1Intern / Fresher
    What is the difference between var, let and const in JavaScript?

    var is function-scoped and can be redeclared; let and const are block-scoped, and const cannot be reassigned after it is set.

  2. Q2Intern / Fresher
    What is the difference between == and === in JavaScript?

    == compares values after type coercion, while === compares both value and type with no conversion, so it is the safer default.

  3. Q3Intern / Fresher
    What is hoisting in JavaScript?

    Hoisting is JavaScript moving declarations to the top of their scope during compilation, so functions and var variables can be referenced before the line where they are written.

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

    undefined means a variable has been declared but no value was assigned; null is an explicit value meaning 'no value' that you assign on purpose.

  5. Q5Intern / Fresher
    What is the difference between map, filter and reduce in JavaScript?

    map transforms every item into a new array of the same length, filter keeps only items that pass a test, and reduce folds the whole array into a single value.

Junior (0-2 years)

  1. Q1Junior (0-2 years)
    What is a closure in JavaScript and why is it useful?

    A closure is a function that keeps access to the variables of the scope where it was created, even after that outer function has finished running.

  2. Q2Junior (0-2 years)
    How does the this keyword work in JavaScript?

    this is decided by how a function is called, not where it is written: as a method it is the object before the dot, with new it is the new object, and arrow functions inherit it from the enclosing scope.

  3. Q3Junior (0-2 years)
    What is the difference between promises and async/await in JavaScript?

    async/await is syntax built on top of promises that lets you write asynchronous code that reads like synchronous code; under the hood every async function returns a promise.

  4. Q4Junior (0-2 years)
    What is event delegation in JavaScript?

    Event delegation means attaching one listener to a parent element and using event bubbling to handle events from its children, instead of adding a listener to each child.

Mid-level (2-5 years)

  1. Q1Mid-level (2-5 years)
    What is the event loop in JavaScript and how does it work?

    The event loop is the mechanism that lets single-threaded JavaScript handle asynchronous work: it runs the call stack to empty, then runs all queued microtasks (promises), then takes the next task (timers, events) from the queue.

  2. Q2Mid-level (2-5 years)
    What is prototypal inheritance in JavaScript?

    In JavaScript every object has an internal link to another object called its prototype, and property lookups walk up this prototype chain until the property is found or the chain ends.

  3. Q3Mid-level (2-5 years)
    What is the difference between debounce and throttle in JavaScript?

    Debounce waits until the user stops triggering an event for a set time before running the function; throttle runs the function at most once per time interval no matter how often the event fires.

Senior (5+ years)

  1. Q1Senior (5+ years)
    How do you find and fix memory leaks in JavaScript?

    Take heap snapshots in Chrome DevTools before and after the suspect action, compare what grew, and fix the retaining reference, which is usually a forgotten listener, timer, global variable or unbounded cache.