Closures

hard

Complete guide with examples and interview questions · 35 min

Definition

Say it out loud in an interview — clear, simple, no textbook wording.

A closure forms when a function is defined inside another function and remembers variables from the outer scope — even after the outer function has returned.

Closures are the mechanism behind encapsulation in JavaScript without classes.

Quick Stats
35
Minutes
hard
Difficulty
4
Interview Q's

Key takeaways

  • A closure is a function plus its lexical environment
  • Inner functions retain access to outer variables after the outer function returns
  • Closures power private state, callbacks, and partial application
  • Classic loop-with-var interview trap tests closure understanding

Track your mastery

Sign in to save Q&A scores, coding challenge progress, points, and streaks across devices.

Sign in to save progress