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 a closure in JavaScript?

    A closure is a function that remembers the variables from the place where it was created, even after that outer function has finished running.

    BeginnerIn-depth2 min read
  2. What is the difference between var, let and const? Explain hoisting and the temporal dead zone.

    var is function-scoped and is hoisted with the value undefined. let and const are block-scoped and are hoisted too, but cannot be used before their declaration line; that gap is the temporal dead zone. const also cannot be reassigned, though an object it holds can still be changed.

    BeginnerIn-depth3 min read
  3. What is an IIFE and why would you use one?

    An IIFE (immediately invoked function expression) is a function that is defined and called in one go, like (function () { ... })(). It creates a private scope so variables inside do not leak out.

    BeginnerQuick answer1 min read
  4. What is lexical scope in JavaScript?

    Lexical scope means a function's accessible variables are decided by where it is written in the source code, not by where it is called. Inner code can see outer variables, never the reverse.

    BeginnerQuick answer1 min read
  5. What is the scope chain and how does JavaScript look up a variable?

    The scope chain is the list of scopes from the current one outward to global. When you use a name, the engine checks the innermost scope first and moves outward until it finds it, or throws a ReferenceError.

    BeginnerQuick answer1 min read