Launch your tech mastery with us—your coding journey starts now!

The Ultimate JavaScript Interview Cheat Sheet (2026 Edition)

Preparing for a Frontend or Full Stack interview? You are in the right place. JavaScript interviews have evolved. It is no longer enough to just know how to write a function; you need to understand how the JavaScript Engine executes it.

In this guide, I have broken down the top 50+ interview topics into simple, bite-sized answers. We will cover everything: Execution Context, Closures, Asynchronous JavaScript, and even how to write your own Polyfills for functions like map, filter, and Promise.all. Bookmark this page—this is the last revision guide you will ever need.

Chapter 1: How JavaScript Works (The Engine)

  1. Execution Context

Think of this as the “environment” where your code runs. Every time a script runs, a Global Execution Context is created. It has two parts:

  • Memory Component (Variable Environment): Where variables and functions are stored as key-value pairs.
  • Code Component (Thread of Execution): Where code is executed line by line.
  1. Call Stack

This is a stack data structure that tracks where we are in the program.

  • When a function is invoked, its context is pushed onto the stack.
  • When it returns, it is popped off.
  1. JavaScript is Single-Threaded

It means JavaScript has only one call stack and can only do one thing at a time. It executes code synchronously (line-by-line).

  1. Hoisting

This is a phenomenon where you can access variables and functions before you initialize them.

  • Why? In the Memory Creation phase (before execution), JS allocates memory for variables (set to undefined) and functions (copies the whole code).
  • Interview Tip: “Hoisting is not moving code to the top physically; it’s about memory allocation before execution.”
  1. Scope & Lexical Environment

  • Scope: Where you can access a specific variable.
  • Lexical Environment: The local memory along with the lexical environment of its parent.
  • Scope Chain: If the engine can’t find a variable in the current scope, it looks up the chain to the parent, then the grandparent, all the way to the global scope.

Chapter 2: Variables & Data Types

  1. Var, Let, and Const

  • Var: Function-scoped, can be redeclared, and is hoisted (initialized as undefined).
  • Let: Block-scoped, cannot be redeclared in the same scope.
  • Const: Block-scoped, must be initialized immediately, cannot be reassigned.
  1. Temporal Dead Zone (TDZ)

The time between the hoisting of a let or const variable and the line where it is actually initialized. Trying to access the variable in the TDZ throws a ReferenceError.

  1. Block Scope

A block is defined by {}. Variables declared with let and const inside these braces are not accessible outside of them. var ignores these blocks (unless it’s a function).

  1. Primitive vs. Non-Primitive

  • Primitive (Value Types): String, Number, Boolean, Null, Undefined, Symbol, BigInt. Stored directly in the stack.
  • Non-Primitive (Reference Types): Objects, Arrays, Functions. Stored in the Heap; the variable holds a pointer (reference) to the location.
  1. Type Coercion vs. Conversion

  • Conversion (Explicit): You manually change the type (e.g., Number(“123”)).
  • Coercion (Implicit): JS automatically changes the type (e.g., “5” – 1 = 4 because JS coerces the string to a number for subtraction).
  1. Null vs. Undefined vs. Not-Defined

  • Undefined: Variable is declared but no value is assigned yet.
  • Null: An assignment value representing “no value” or “empty.”
  • Not-Defined: The variable has not been declared at all (throws ReferenceError).

Chapter 3: Functions ( The Heart of JS)

  1. First Class Functions

Functions are treated like variables. You can pass them as arguments, return them from other functions, and assign them to variables.

  1. Closures

A function bundled together with its lexical environment.

  • In simple words: A function “remembers” the variables around it even when it is executed elsewhere.
  • Use case: Data hiding, memoization.
  1. Currying

Transforming a function with multiple arguments f(a, b) into a sequence of functions f(a)(b).

  • Infinite Currying: A function that keeps returning another function until you stop calling it (often used to sum infinite numbers: sum(1)(2)(3)…()).
  1. High Order Functions (HOF)

A function that takes another function as an argument OR returns a function. (e.g., .map(), .filter(), setTimeout).

  1. Call, Apply, Bind

Methods to manually set the value of this.

  • Call: Invokes function immediately, arguments passed individually.
  • Apply: Invokes function immediately, arguments passed as an array.
  • Bind: Returns a new function with this bound (does not invoke immediately).
  1. IIFE (Immediately Invoked Function Expression)

A function that runs as soon as it is defined. Used to avoid polluting the global scope.

(function() { … })();

  1. Arrow Functions vs. Regular Functions

  • Syntax: Arrow functions are shorter.
  • this keyword: Arrow functions do not have their own this; they inherit it from the surrounding (lexical) scope. Regular functions have a dynamic this depending on how they are called.

Chapter 4: Objects & Prototypes

  1. Prototypes & Prototype Chain

  • Every object in JS has a hidden property called [[Prototype]].
  • If you access a property that doesn’t exist on an object, JS looks at its prototype, then the prototype’s prototype, until it hits null. This is the Prototype Chain.
  1. Ways to Create Objects

  1. Object Literal {}
  2. new Object()
  3. Object.create()
  4. Constructor Functions
  5. Classes (ES6)
  1. Pass by Value vs. Reference

  • Primitives: Pass a copy of the value. Changing the copy doesn’t affect the original.
  • Objects: Pass the reference (address). Changing the object inside a function affects the original object outside.
  1. this Keyword

  • In Global space: window (or global in Node).
  • Inside a method: Refers to the object owning the method.
  • In Strict Mode: undefined inside a function (unless called on an object).

Chapter 5: Asynchronous JavaScript (The Loop)

  1. Callback Hell

When you nest multiple callbacks inside each other (Pyramid of Doom). It makes code unreadable and hard to maintain. Solved by Promises.

  1. Promises

An object representing the eventual completion (or failure) of an asynchronous operation.

  • States: Pending, Fulfilled, Rejected.
  • Methods: .then(), .catch(), .finally().
  1. Async / Await

Syntactic sugar over Promises. It makes async code look and behave like synchronous code.

  1. Event Loop

The mechanism that handles async operations in JS.

  • It constantly checks: Is the Call Stack empty?
  • If yes, it pushes tasks from the Callback Queue to the Call Stack.
  1. Callback Queue vs. Microtask Queue

  • Microtask Queue: Higher priority. Stores Promises and Mutation Observer callbacks.
  • Callback Queue (Task Queue): Lower priority. Stores setTimeout, DOM events, etc.
  • The Event Loop always empties the Microtask Queue before the Callback Queue.
  1. Infinite Microtask Loop

If a microtask recursively queues another microtask, the Call Stack will never get a chance to run tasks from the Callback Queue or render UI. The browser will freeze.

Chapter 6: The DOM & Events

  1. Event Bubbling vs. Capturing

  • Bubbling: Event triggers on the target element first, then bubbles UP to ancestors (default).
  • Capturing (Trickling): Event triggers on the root ancestor first, then goes DOWN to the target.
  1. Event Delegation

Instead of adding event listeners to multiple child elements, you add one listener to the parent. You use the event.target property to catch the event bubbling up. This saves memory.

  1. Debounce vs. Throttle

Optimization techniques for high-frequency events (like scrolling or resizing).

  • Debounce: “Wait until the user stops.” (e.g., Search bar: only search 300ms after the user stops typing).
  • Throttle: “Run at a regular interval.” (e.g., Shooting game: can only fire once every 100ms, no matter how fast you click).

Chapter 7: Advanced Concepts

  1. Garbage Collection

JS automatically frees up memory. It uses the Mark and Sweep algorithm: “If I cannot reach this object from the root (global), it is garbage.”

  1. Generator Functions

Functions that can be paused and resumed. Marked with *. Use yield to pause execution.

  1. Rest vs. Spread Operator (…)

  • Rest: Collects remaining arguments into an array. function(…args).
  • Spread: Expands an array/object into individual elements. […arr1, …arr2].
  1. Memoization

An optimization technique. It involves caching the result of a function based on its arguments. If the function is called again with the same args, return the cached result instead of recalculating.

  1. Variable Shadowing

When a variable in a local scope has the same name as a variable in a parent scope. The local variable “shadows” (hides) the outer one.

Leave a Reply

Your email address will not be published. Required fields are marked *