What is closure in JavaScript?

A closure is the combination of a function bundled together i.e., enclosed with references to its surrounding state i.e., the lexical environment. In other words, a closure gives the users, access to an outer function’s scope from an inner function. In JavaScript, closures are created every time a function is created, at function creation time.