JavaScriptIntermediate#closures#functions

What is a closure?

A function bundled with the lexical scope it was created in, so it keeps access to those outer variables after the outer function returns. Closures power private state, memoization and function factories.

Example
function counter() {
  let count = 0;
  return () => ++count;
}
const inc = counter();
inc(); // 1
inc(); // 2

Related Questions

1
JavaScriptBeginner#operators#coercion

Explain == vs ===.

Open
2
JavaScriptBeginner#coercion

What are truthy and falsy values?

Open
3
JavaScriptIntermediate#this#functions

How does 'this' work in JavaScript?

Open