🎁 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

Regex (Regular Expression)
A sequence of characters that defines a search pattern, used for string matching, validation, and text manipulation.
Design Pattern
A reusable solution template for commonly occurring problems in software design.
Code Smell
A surface indication in code that usually corresponds to a deeper problem in the system, suggesting the need for refactoring.
Singleton Pattern
A design pattern that restricts a class to a single instance and provides a global point of access to that instance.
Composition over Inheritance
A design principle favoring object composition (has-a relationships) over class inheritance (is-a relationships) for code reuse.
Functional Programming
A programming paradigm that treats computation as the evaluation of mathematical functions, avoiding state changes and mutable data.
View All Programming Concepts Terms →