Interview Q&A / JavaScript

INTERVIEW Q&A · 71 QUESTIONS

JavaScript interview questions

Closures, the event loop, this, promises and the core language questions every frontend round asks.

  1. What is the difference between debounce and throttle? Implement both.

    Debounce waits until calls stop for a set time and then runs the function once, like search-as-you-type. Throttle runs the function at most once per time window no matter how often it is called, like handling scroll events. Both are built with a closure that holds a timer or a timestamp.

    IntermediateIn-depthCoding3 min read
  2. How can you create private variables in JavaScript using closures?

    Declare the variable inside a function and return only functions that use it. The variable lives on in the closure, but no outside code can read or change it directly.

    IntermediateQuick answer1 min read
  3. Write a memoize function that caches the results of a pure function.

    Wrap the function and store results in a Map keyed by its arguments. If the key exists, return the cached value; otherwise compute, store and return. It only works safely for pure functions.

    IntermediateQuick answerCoding1 min read