🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

Programming Concepts Intermediate

What is Closure?

A function that captures and retains access to variables from its enclosing scope, even after that scope has finished executing.

A closure "closes over" variables from its surrounding environment. In JavaScript: function outer() { let count = 0; return function() { return ++count; }; }. The inner function retains access to count even after outer() returns.

Closures enable data encapsulation (private variables), callbacks, event handlers, partial application, and memoization. They are fundamental to functional programming and used extensively in JavaScript, Python, Ruby, and Swift.

Related Terms

Data Structure
A way of organizing and storing data in a computer so it can be accessed and modified efficiently.
Event-Driven Architecture
A software design pattern where components communicate by producing and consuming events rather than direct method calls.
Recursion
A programming technique where a function calls itself to solve a problem by breaking it into smaller subproblems.
Singleton Pattern
A design pattern that restricts a class to a single instance and provides a global point of access to that instance.
Clean Code
Code that is easy to read, understand, and maintain — following consistent conventions, meaningful naming, and single-responsibility functions.
DRY (Don't Repeat Yourself)
A software development principle that aims to reduce code duplication by abstracting common patterns into reusable components.
View All Programming Concepts Terms →