A closure in JavaScript is a function that has access to its own scope, the outer function’s scope, and the global scope. Closures have access to their own scope (variables defined between its curly braces), the outer function’s variables, and the global variables.
A closure is created when a function is returned from another function, retaining its lexical scope, i.e., it has access to the variables in the outer function scope even after the outer function has returned. This implies that JavaScript functions have a ‘memory’.
Closures are commonly used to create private variables or functions, essentially forming the basis for JavaScript module patterns.